1/*
2 * Copyright (C) 2009 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 AVC_DECODER_H_
18
19#define AVC_DECODER_H_
20
21#include <media/stagefright/MediaBuffer.h>
22#include <media/stagefright/MediaSource.h>
23#include <utils/Vector.h>
24
25struct tagAVCHandle;
26
27namespace android {
28
29struct AVCDecoder : public MediaSource,
30                    public MediaBufferObserver {
31    AVCDecoder(const sp<MediaSource> &source);
32
33    virtual status_t start(MetaData *params);
34    virtual status_t stop();
35
36    virtual sp<MetaData> getFormat();
37
38    virtual status_t read(
39            MediaBuffer **buffer, const ReadOptions *options);
40
41    virtual void signalBufferReturned(MediaBuffer *buffer);
42
43protected:
44    virtual ~AVCDecoder();
45
46private:
47    sp<MediaSource> mSource;
48    bool mStarted;
49
50    sp<MetaData> mFormat;
51
52    Vector<MediaBuffer *> mCodecSpecificData;
53
54    tagAVCHandle *mHandle;
55    Vector<MediaBuffer *> mFrames;
56    MediaBuffer *mInputBuffer;
57
58    int64_t mAnchorTimeUs;
59    int64_t mNumSamplesOutput;
60    int64_t mPendingSeekTimeUs;
61    MediaSource::ReadOptions::SeekMode mPendingSeekMode;
62
63    int64_t mTargetTimeUs;
64
65    bool mSPSSeen;
66    bool mPPSSeen;
67
68    void addCodecSpecificData(const uint8_t *data, size_t size);
69
70    static int32_t ActivateSPSWrapper(
71            void *userData, unsigned int sizeInMbs, unsigned int numBuffers);
72
73    static int32_t BindFrameWrapper(
74            void *userData, int32_t index, uint8_t **yuv);
75
76    static void UnbindFrame(void *userData, int32_t index);
77
78    int32_t activateSPS(
79            unsigned int sizeInMbs, unsigned int numBuffers);
80
81    int32_t bindFrame(int32_t index, uint8_t **yuv);
82
83    void releaseFrames();
84
85    MediaBuffer *drainOutputBuffer();
86
87    AVCDecoder(const AVCDecoder &);
88    AVCDecoder &operator=(const AVCDecoder &);
89};
90
91}  // namespace android
92
93#endif  // AVC_DECODER_H_
94