blob: dba3eeeb1bb5728bba267c3de490e4c2b6504c22 [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;
Lajos Molnar09524832014-07-17 14:29:51 -070029struct MediaBuffer;
Andreas Huberf9334412010-12-15 15:17:42 -080030
31struct NuPlayer::Decoder : public AHandler {
Glenn Kasten11731182011-02-08 17:26:17 -080032 Decoder(const sp<AMessage> &notify,
33 const sp<NativeWindowWrapper> &nativeWindow = NULL);
Andreas Huberf9334412010-12-15 15:17:42 -080034
Wei Jiabc2fb722014-07-08 16:37:57 -070035 virtual void configure(const sp<AMessage> &format);
36 virtual void init();
Andreas Huber3831a062010-12-21 10:22:33 -080037
Lajos Molnar09524832014-07-17 14:29:51 -070038 status_t getInputBuffers(Vector<sp<ABuffer> > *dstBuffers) const;
Lajos Molnar87603c02014-08-20 19:25:30 -070039 virtual void signalFlush(const sp<AMessage> &format = NULL);
40 virtual void signalUpdateFormat(const sp<AMessage> &format);
Wei Jiabc2fb722014-07-08 16:37:57 -070041 virtual void signalResume();
42 virtual void initiateShutdown();
Andreas Huberf9334412010-12-15 15:17:42 -080043
Wei Jiabc2fb722014-07-08 16:37:57 -070044 virtual bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
Robert Shih6d0a94e2014-01-23 16:18:22 -080045
Lajos Molnar1cd13982014-01-17 15:12:51 -080046 enum {
47 kWhatFillThisBuffer = 'flTB',
48 kWhatDrainThisBuffer = 'drTB',
49 kWhatOutputFormatChanged = 'fmtC',
50 kWhatFlushCompleted = 'flsC',
51 kWhatShutdownCompleted = 'shDC',
52 kWhatEOS = 'eos ',
53 kWhatError = 'err ',
54 };
55
Andreas Huberf9334412010-12-15 15:17:42 -080056protected:
Lajos Molnar1cd13982014-01-17 15:12:51 -080057
Andreas Huberf9334412010-12-15 15:17:42 -080058 virtual ~Decoder();
59
60 virtual void onMessageReceived(const sp<AMessage> &msg);
61
62private:
63 enum {
Andreas Huber078cfcf2011-09-15 12:25:04 -070064 kWhatCodecNotify = 'cdcN',
Lajos Molnar1cd13982014-01-17 15:12:51 -080065 kWhatConfigure = 'conf',
Lajos Molnar09524832014-07-17 14:29:51 -070066 kWhatGetInputBuffers = 'gInB',
Lajos Molnar1cd13982014-01-17 15:12:51 -080067 kWhatInputBufferFilled = 'inpF',
68 kWhatRenderBuffer = 'rndr',
69 kWhatFlush = 'flus',
70 kWhatShutdown = 'shuD',
Lajos Molnar87603c02014-08-20 19:25:30 -070071 kWhatUpdateFormat = 'uFmt',
Andreas Huberf9334412010-12-15 15:17:42 -080072 };
73
74 sp<AMessage> mNotify;
Glenn Kasten11731182011-02-08 17:26:17 -080075 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -080076
Lajos Molnar1cd13982014-01-17 15:12:51 -080077 sp<AMessage> mInputFormat;
78 sp<AMessage> mOutputFormat;
79 sp<MediaCodec> mCodec;
Andreas Huber078cfcf2011-09-15 12:25:04 -070080 sp<ALooper> mCodecLooper;
Lajos Molnar1cd13982014-01-17 15:12:51 -080081 sp<ALooper> mDecoderLooper;
Andreas Huberf9334412010-12-15 15:17:42 -080082
Wei Jia2245fc62014-10-02 15:12:25 -070083 List<sp<AMessage> > mPendingInputMessages;
84
Lajos Molnar1cd13982014-01-17 15:12:51 -080085 Vector<sp<ABuffer> > mInputBuffers;
86 Vector<sp<ABuffer> > mOutputBuffers;
Lajos Molnar87603c02014-08-20 19:25:30 -070087 Vector<sp<ABuffer> > mCSDsForCurrentFormat;
88 Vector<sp<ABuffer> > mCSDsToSubmit;
Lajos Molnar09524832014-07-17 14:29:51 -070089 Vector<bool> mInputBufferIsDequeued;
90 Vector<MediaBuffer *> mMediaBuffers;
Andreas Huberf9334412010-12-15 15:17:42 -080091
Lajos Molnar1cd13982014-01-17 15:12:51 -080092 void handleError(int32_t err);
93 bool handleAnInputBuffer();
94 bool handleAnOutputBuffer();
Andreas Huberf9334412010-12-15 15:17:42 -080095
Lajos Molnar09524832014-07-17 14:29:51 -070096 void releaseAndResetMediaBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -080097 void requestCodecNotification();
98 bool isStaleReply(const sp<AMessage> &msg);
99
100 void onConfigure(const sp<AMessage> &format);
101 void onFlush();
Wei Jia704e7262014-06-04 16:21:56 -0700102 void onResume();
Wei Jia2245fc62014-10-02 15:12:25 -0700103 bool onInputBufferFilled(const sp<AMessage> &msg);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800104 void onRenderBuffer(const sp<AMessage> &msg);
105 void onShutdown();
106
107 int32_t mBufferGeneration;
Wei Jia704e7262014-06-04 16:21:56 -0700108 bool mPaused;
Lajos Molnar1cd13982014-01-17 15:12:51 -0800109 AString mComponentName;
Andreas Huberf9334412010-12-15 15:17:42 -0800110
Robert Shih6d0a94e2014-01-23 16:18:22 -0800111 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
Lajos Molnar87603c02014-08-20 19:25:30 -0700112 void rememberCodecSpecificData(const sp<AMessage> &format);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800113
Andreas Huberf9334412010-12-15 15:17:42 -0800114 DISALLOW_EVIL_CONSTRUCTORS(Decoder);
115};
116
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700117struct NuPlayer::CCDecoder : public RefBase {
118 enum {
119 kWhatClosedCaptionData,
120 kWhatTrackAdded,
121 };
122
123 CCDecoder(const sp<AMessage> &notify);
124
125 size_t getTrackCount() const;
126 sp<AMessage> getTrackInfo(size_t index) const;
127 status_t selectTrack(size_t index, bool select);
128 bool isSelected() const;
129 void decode(const sp<ABuffer> &accessUnit);
130 void display(int64_t timeUs);
Chong Zhangb86e68f2014-08-01 13:46:53 -0700131 void flush();
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700132
133private:
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700134 sp<AMessage> mNotify;
135 KeyedVector<int64_t, sp<ABuffer> > mCCMap;
Chong Zhangb86e68f2014-08-01 13:46:53 -0700136 size_t mCurrentChannel;
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700137 int32_t mSelectedTrack;
Chong Zhangb86e68f2014-08-01 13:46:53 -0700138 int32_t mTrackIndices[4];
139 Vector<size_t> mFoundChannels;
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700140
Chong Zhangb86e68f2014-08-01 13:46:53 -0700141 bool isTrackValid(size_t index) const;
142 int32_t getTrackIndex(size_t channel) const;
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700143 bool extractFromSEI(const sp<ABuffer> &accessUnit);
Chong Zhangb86e68f2014-08-01 13:46:53 -0700144 sp<ABuffer> filterCCBuf(const sp<ABuffer> &ccBuf, size_t index);
Chong Zhanga7fa1d92014-06-11 14:49:23 -0700145
146 DISALLOW_EVIL_CONSTRUCTORS(CCDecoder);
147};
148
Andreas Huberf9334412010-12-15 15:17:42 -0800149} // namespace android
150
151#endif // NUPLAYER_DECODER_H_