1f933441648ef6a71dee783d733aac17b9508b452Andreas Huber/*
27137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang * Copyright 2014 The Android Open Source Project
3f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
4f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * you may not use this file except in compliance with the License.
6f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * You may obtain a copy of the License at
7f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
8f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
10f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Unless required by applicable law or agreed to in writing, software
11f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * See the License for the specific language governing permissions and
14f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * limitations under the License.
15f933441648ef6a71dee783d733aac17b9508b452Andreas Huber */
16f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
17f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#ifndef NUPLAYER_DECODER_H_
18f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#define NUPLAYER_DECODER_H_
19f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
20f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include "NuPlayer.h"
21f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
227137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang#include "NuPlayerDecoderBase.h"
23f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
24f933441648ef6a71dee783d733aac17b9508b452Andreas Hubernamespace android {
25f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
267137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhangstruct NuPlayer::Decoder : public DecoderBase {
271173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    Decoder(const sp<AMessage> &notify,
28c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia            const sp<Source> &source,
29c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia            const sp<Renderer> &renderer = NULL,
307137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang            const sp<NativeWindowWrapper> &nativeWindow = NULL,
317137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang            const sp<CCDecoder> &ccDecoder = NULL);
32c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia
337137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    virtual void getStats(
347137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang            int64_t *mNumFramesTotal,
357137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang            int64_t *mNumFramesDropped) const;
361cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar
37f933441648ef6a71dee783d733aac17b9508b452Andreas Huberprotected:
38f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual ~Decoder();
39f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
40f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual void onMessageReceived(const sp<AMessage> &msg);
41f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
427137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    virtual void onConfigure(const sp<AMessage> &format);
437137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    virtual void onSetRenderer(const sp<Renderer> &renderer);
447137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers);
45f8d717772f6d185cb07720cd5091df9b7d612e0bChong Zhang    virtual void onResume(bool notifyComplete);
467137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    virtual void onFlush(bool notifyComplete);
477137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    virtual void onShutdown(bool notifyComplete);
487137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    virtual void doRequestBuffers();
497137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang
507137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhangprivate:
51f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    enum {
527137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang        kWhatCodecNotify         = 'cdcN',
537137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang        kWhatRenderBuffer        = 'rndr',
54f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    };
55f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
561173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    sp<NativeWindowWrapper> mNativeWindow;
57f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
58c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia    sp<Source> mSource;
59c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia    sp<Renderer> mRenderer;
607137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    sp<CCDecoder> mCCDecoder;
61c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia
621cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    sp<AMessage> mInputFormat;
631cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    sp<AMessage> mOutputFormat;
641cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    sp<MediaCodec> mCodec;
65078cfcf7cce9185ec7559910d08b0bc02bfc88a3Andreas Huber    sp<ALooper> mCodecLooper;
661cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar
672245fc625910e47d1ba3c339e205c21ab58a47adWei Jia    List<sp<AMessage> > mPendingInputMessages;
682245fc625910e47d1ba3c339e205c21ab58a47adWei Jia
691cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    Vector<sp<ABuffer> > mInputBuffers;
701cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    Vector<sp<ABuffer> > mOutputBuffers;
7187603c0dd1f4e62e52feffa8d6e960ad21f68893Lajos Molnar    Vector<sp<ABuffer> > mCSDsForCurrentFormat;
7287603c0dd1f4e62e52feffa8d6e960ad21f68893Lajos Molnar    Vector<sp<ABuffer> > mCSDsToSubmit;
73095248375e29adde961ec2a44989ecb3a6dda6a2Lajos Molnar    Vector<bool> mInputBufferIsDequeued;
74095248375e29adde961ec2a44989ecb3a6dda6a2Lajos Molnar    Vector<MediaBuffer *> mMediaBuffers;
757137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    Vector<size_t> mDequeuedInputBuffers;
761cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar
77c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia    int64_t mSkipRenderingUntilMediaTimeUs;
787137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    int64_t mNumFramesTotal;
797137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    int64_t mNumFramesDropped;
807137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    bool mIsAudio;
817137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    bool mIsVideoAVC;
827137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    bool mIsSecure;
837137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    bool mFormatChangePending;
847137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang
857137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    bool mPaused;
86f8d717772f6d185cb07720cd5091df9b7d612e0bChong Zhang    bool mResumePending;
877137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    AString mComponentName;
88c6cfd70f24a11b946859485ce398a189c301a4e2Wei Jia
891cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    bool handleAnInputBuffer();
901cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    bool handleAnOutputBuffer();
91f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
92095248375e29adde961ec2a44989ecb3a6dda6a2Lajos Molnar    void releaseAndResetMediaBuffers();
931cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    void requestCodecNotification();
941cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    bool isStaleReply(const sp<AMessage> &msg);
95f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
967137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    status_t fetchInputData(sp<AMessage> &reply);
977137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    bool onInputBufferFetched(const sp<AMessage> &msg);
981cd139824b2e6832f239cd27d8962d3239053c02Lajos Molnar    void onRenderBuffer(const sp<AMessage> &msg);
99f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
1007137ec7e005a5a6e3c0edb91cfacf16a31f4bf6aChong Zhang    bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
1016d0a94ead4f6e62b8ca9b2b1d775ffcd0a7a7aabRobert Shih    bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
10287603c0dd1f4e62e52feffa8d6e960ad21f68893Lajos Molnar    void rememberCodecSpecificData(const sp<AMessage> &format);
1036d0a94ead4f6e62b8ca9b2b1d775ffcd0a7a7aabRobert Shih
104f8d717772f6d185cb07720cd5091df9b7d612e0bChong Zhang    void notifyResumeCompleteIfNecessary();
105f8d717772f6d185cb07720cd5091df9b7d612e0bChong Zhang
106f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(Decoder);
107f933441648ef6a71dee783d733aac17b9508b452Andreas Huber};
108f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
109f933441648ef6a71dee783d733aac17b9508b452Andreas Huber}  // namespace android
110f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
111f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#endif  // NUPLAYER_DECODER_H_
112