blob: 94243fc01589697f218781d71020a2015cfdc8fc [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef NUPLAYER_DECODER_H_
18
19#define NUPLAYER_DECODER_H_
20
21#include "NuPlayer.h"
22
23#include <media/stagefright/foundation/AHandler.h>
24
25namespace android {
26
Andreas Huber5bc087c2010-12-23 10:27:40 -080027struct ABuffer;
Lajos Molnar1cd13982014-01-17 15:12:51 -080028struct MediaCodec;
Andreas Huberf9334412010-12-15 15:17:42 -080029
30struct NuPlayer::Decoder : public AHandler {
Glenn Kasten11731182011-02-08 17:26:17 -080031 Decoder(const sp<AMessage> &notify,
32 const sp<NativeWindowWrapper> &nativeWindow = NULL);
Andreas Huberf9334412010-12-15 15:17:42 -080033
Andreas Huber84066782011-08-16 09:34:26 -070034 void configure(const sp<AMessage> &format);
Lajos Molnar1cd13982014-01-17 15:12:51 -080035 void init();
Andreas Huber3831a062010-12-21 10:22:33 -080036
Andreas Huberf9334412010-12-15 15:17:42 -080037 void signalFlush();
38 void signalResume();
Andreas Huber3831a062010-12-21 10:22:33 -080039 void initiateShutdown();
Andreas Huberf9334412010-12-15 15:17:42 -080040
Robert Shih6d0a94e2014-01-23 16:18:22 -080041 bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
42
Lajos Molnar1cd13982014-01-17 15:12:51 -080043 enum {
44 kWhatFillThisBuffer = 'flTB',
45 kWhatDrainThisBuffer = 'drTB',
46 kWhatOutputFormatChanged = 'fmtC',
47 kWhatFlushCompleted = 'flsC',
48 kWhatShutdownCompleted = 'shDC',
49 kWhatEOS = 'eos ',
50 kWhatError = 'err ',
51 };
52
Andreas Huberf9334412010-12-15 15:17:42 -080053protected:
Lajos Molnar1cd13982014-01-17 15:12:51 -080054
Andreas Huberf9334412010-12-15 15:17:42 -080055 virtual ~Decoder();
56
57 virtual void onMessageReceived(const sp<AMessage> &msg);
58
59private:
60 enum {
Andreas Huber078cfcf2011-09-15 12:25:04 -070061 kWhatCodecNotify = 'cdcN',
Lajos Molnar1cd13982014-01-17 15:12:51 -080062 kWhatConfigure = 'conf',
63 kWhatInputBufferFilled = 'inpF',
64 kWhatRenderBuffer = 'rndr',
65 kWhatFlush = 'flus',
66 kWhatShutdown = 'shuD',
Andreas Huberf9334412010-12-15 15:17:42 -080067 };
68
69 sp<AMessage> mNotify;
Glenn Kasten11731182011-02-08 17:26:17 -080070 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -080071
Lajos Molnar1cd13982014-01-17 15:12:51 -080072 sp<AMessage> mInputFormat;
73 sp<AMessage> mOutputFormat;
74 sp<MediaCodec> mCodec;
Andreas Huber078cfcf2011-09-15 12:25:04 -070075 sp<ALooper> mCodecLooper;
Lajos Molnar1cd13982014-01-17 15:12:51 -080076 sp<ALooper> mDecoderLooper;
Andreas Huberf9334412010-12-15 15:17:42 -080077
Lajos Molnar1cd13982014-01-17 15:12:51 -080078 Vector<sp<ABuffer> > mInputBuffers;
79 Vector<sp<ABuffer> > mOutputBuffers;
Andreas Huberf9334412010-12-15 15:17:42 -080080
Lajos Molnar1cd13982014-01-17 15:12:51 -080081 void handleError(int32_t err);
82 bool handleAnInputBuffer();
83 bool handleAnOutputBuffer();
Andreas Huberf9334412010-12-15 15:17:42 -080084
Lajos Molnar1cd13982014-01-17 15:12:51 -080085 void requestCodecNotification();
86 bool isStaleReply(const sp<AMessage> &msg);
87
88 void onConfigure(const sp<AMessage> &format);
89 void onFlush();
90 void onInputBufferFilled(const sp<AMessage> &msg);
91 void onRenderBuffer(const sp<AMessage> &msg);
92 void onShutdown();
93
94 int32_t mBufferGeneration;
95 AString mComponentName;
Andreas Huberf9334412010-12-15 15:17:42 -080096
Robert Shih6d0a94e2014-01-23 16:18:22 -080097 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
98
Andreas Huberf9334412010-12-15 15:17:42 -080099 DISALLOW_EVIL_CONSTRUCTORS(Decoder);
100};
101
102} // namespace android
103
104#endif // NUPLAYER_DECODER_H_