NuPlayerDecoder.h revision a7fa1d9530b6870f2c7850e3025d7db963661803
1/*
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
27struct ABuffer;
28struct MediaCodec;
29
30struct NuPlayer::Decoder : public AHandler {
31    Decoder(const sp<AMessage> &notify,
32            const sp<NativeWindowWrapper> &nativeWindow = NULL);
33
34    void configure(const sp<AMessage> &format);
35    void init();
36
37    void signalFlush();
38    void signalResume();
39    void initiateShutdown();
40
41    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
42
43    enum {
44        kWhatFillThisBuffer      = 'flTB',
45        kWhatDrainThisBuffer     = 'drTB',
46        kWhatOutputFormatChanged = 'fmtC',
47        kWhatFlushCompleted      = 'flsC',
48        kWhatShutdownCompleted   = 'shDC',
49        kWhatEOS                 = 'eos ',
50        kWhatError               = 'err ',
51    };
52
53protected:
54
55    virtual ~Decoder();
56
57    virtual void onMessageReceived(const sp<AMessage> &msg);
58
59private:
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> &notify);
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