NuPlayerDecoder.h revision bc2fb720bbd0acd122bacc67e844e982d068f6f9
12c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* 22c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2010 The Android Open Source Project 32c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * 42c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Licensed under the Apache License, Version 2.0 (the "License"); 52c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * you may not use this file except in compliance with the License. 62c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * You may obtain a copy of the License at 72c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * 82c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * http://www.apache.org/licenses/LICENSE-2.0 92c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * 102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Unless required by applicable law or agreed to in writing, software 112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * distributed under the License is distributed on an "AS IS" BASIS, 122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * See the License for the specific language governing permissions and 142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * limitations under the License. 152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent */ 162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#ifndef NUPLAYER_DECODER_H_ 182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define NUPLAYER_DECODER_H_ 202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include "NuPlayer.h" 222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <media/stagefright/foundation/AHandler.h> 242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace android { 262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstruct ABuffer; 282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstruct MediaCodec; 292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentstruct NuPlayer::Decoder : public AHandler { 312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent Decoder(const sp<AMessage> ¬ify, 322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent const sp<NativeWindowWrapper> &nativeWindow = NULL); 332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual void configure(const sp<AMessage> &format); 352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual void init(); 362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual void signalFlush(); 382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual void signalResume(); 392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual void initiateShutdown(); 402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual bool supportsSeamlessFormatChange(const sp<AMessage> &to) const; 422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent enum { 442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent kWhatFillThisBuffer = 'flTB', 452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent kWhatDrainThisBuffer = 'drTB', 462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent kWhatOutputFormatChanged = 'fmtC', 472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent kWhatFlushCompleted = 'flsC', 482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent kWhatShutdownCompleted = 'shDC', 492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent kWhatEOS = 'eos ', 502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent kWhatError = 'err ', 512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent }; 522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentprotected: 542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual ~Decoder(); 562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent virtual void onMessageReceived(const sp<AMessage> &msg); 582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent 592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentprivate: 60 enum { 61 kWhatCodecNotify = 'cdcN', 62 kWhatConfigure = 'conf', 63 kWhatInputBufferFilled = 'inpF', 64 kWhatRenderBuffer = 'rndr', 65 kWhatFlush = 'flus', 66 kWhatShutdown = 'shuD', 67 }; 68 69 sp<AMessage> mNotify; 70 sp<NativeWindowWrapper> mNativeWindow; 71 72 sp<AMessage> mInputFormat; 73 sp<AMessage> mOutputFormat; 74 sp<MediaCodec> mCodec; 75 sp<ALooper> mCodecLooper; 76 sp<ALooper> mDecoderLooper; 77 78 Vector<sp<ABuffer> > mInputBuffers; 79 Vector<sp<ABuffer> > mOutputBuffers; 80 81 void handleError(int32_t err); 82 bool handleAnInputBuffer(); 83 bool handleAnOutputBuffer(); 84 85 void requestCodecNotification(); 86 bool isStaleReply(const sp<AMessage> &msg); 87 88 void onConfigure(const sp<AMessage> &format); 89 void onFlush(); 90 void onResume(); 91 void onInputBufferFilled(const sp<AMessage> &msg); 92 void onRenderBuffer(const sp<AMessage> &msg); 93 void onShutdown(); 94 95 int32_t mBufferGeneration; 96 bool mPaused; 97 AString mComponentName; 98 99 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const; 100 101 DISALLOW_EVIL_CONSTRUCTORS(Decoder); 102}; 103 104struct NuPlayer::CCDecoder : public RefBase { 105 enum { 106 kWhatClosedCaptionData, 107 kWhatTrackAdded, 108 }; 109 110 CCDecoder(const sp<AMessage> ¬ify); 111 112 size_t getTrackCount() const; 113 sp<AMessage> getTrackInfo(size_t index) const; 114 status_t selectTrack(size_t index, bool select); 115 bool isSelected() const; 116 void decode(const sp<ABuffer> &accessUnit); 117 void display(int64_t timeUs); 118 119private: 120 struct CCData; 121 122 sp<AMessage> mNotify; 123 KeyedVector<int64_t, sp<ABuffer> > mCCMap; 124 size_t mTrackCount; 125 int32_t mSelectedTrack; 126 127 bool isNullPad(CCData *cc) const; 128 void dumpBytePair(const sp<ABuffer> &ccBuf) const; 129 bool extractFromSEI(const sp<ABuffer> &accessUnit); 130 131 DISALLOW_EVIL_CONSTRUCTORS(CCDecoder); 132}; 133 134} // namespace android 135 136#endif // NUPLAYER_DECODER_H_ 137