• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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 #define NUPLAYER_DECODER_H_
19 
20 #include "NuPlayer.h"
21 
22 #include "NuPlayerDecoderBase.h"
23 
24 namespace android {
25 
26 struct NuPlayer::Decoder : public DecoderBase {
27     Decoder(const sp<AMessage> &notify,
28             const sp<Source> &source,
29             pid_t pid,
30             const sp<Renderer> &renderer = NULL,
31             const sp<Surface> &surface = NULL,
32             const sp<CCDecoder> &ccDecoder = NULL);
33 
34     virtual sp<AMessage> getStats() const;
35 
36     // sets the output surface of video decoders.
37     virtual status_t setVideoSurface(const sp<Surface> &surface);
38 
39 protected:
40     virtual ~Decoder();
41 
42     virtual void onMessageReceived(const sp<AMessage> &msg);
43 
44     virtual void onConfigure(const sp<AMessage> &format);
45     virtual void onSetParameters(const sp<AMessage> &params);
46     virtual void onSetRenderer(const sp<Renderer> &renderer);
47     virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers);
48     virtual void onResume(bool notifyComplete);
49     virtual void onFlush();
50     virtual void onShutdown(bool notifyComplete);
51     virtual bool doRequestBuffers();
52 
53 private:
54     enum {
55         kWhatCodecNotify         = 'cdcN',
56         kWhatRenderBuffer        = 'rndr',
57         kWhatSetVideoSurface     = 'sSur'
58     };
59 
60     sp<Surface> mSurface;
61 
62     sp<Source> mSource;
63     sp<Renderer> mRenderer;
64     sp<CCDecoder> mCCDecoder;
65 
66     sp<AMessage> mInputFormat;
67     sp<AMessage> mOutputFormat;
68     sp<MediaCodec> mCodec;
69     sp<ALooper> mCodecLooper;
70 
71     List<sp<AMessage> > mPendingInputMessages;
72 
73     Vector<sp<ABuffer> > mInputBuffers;
74     Vector<sp<ABuffer> > mOutputBuffers;
75     Vector<sp<ABuffer> > mCSDsForCurrentFormat;
76     Vector<sp<ABuffer> > mCSDsToSubmit;
77     Vector<bool> mInputBufferIsDequeued;
78     Vector<MediaBuffer *> mMediaBuffers;
79     Vector<size_t> mDequeuedInputBuffers;
80 
81     const pid_t mPid;
82     int64_t mSkipRenderingUntilMediaTimeUs;
83     int64_t mNumFramesTotal;
84     int64_t mNumInputFramesDropped;
85     int64_t mNumOutputFramesDropped;
86     int32_t mVideoWidth;
87     int32_t mVideoHeight;
88     bool mIsAudio;
89     bool mIsVideoAVC;
90     bool mIsSecure;
91     bool mFormatChangePending;
92     bool mTimeChangePending;
93 
94     bool mResumePending;
95     AString mComponentName;
96 
97     void handleError(int32_t err);
98     bool handleAnInputBuffer(size_t index);
99     bool handleAnOutputBuffer(
100             size_t index,
101             size_t offset,
102             size_t size,
103             int64_t timeUs,
104             int32_t flags);
105     void handleOutputFormatChange(const sp<AMessage> &format);
106 
107     void releaseAndResetMediaBuffers();
108     void requestCodecNotification();
109     bool isStaleReply(const sp<AMessage> &msg);
110 
111     void doFlush(bool notifyComplete);
112     status_t fetchInputData(sp<AMessage> &reply);
113     bool onInputBufferFetched(const sp<AMessage> &msg);
114     void onRenderBuffer(const sp<AMessage> &msg);
115 
116     bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
117     bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
118     void rememberCodecSpecificData(const sp<AMessage> &format);
119     bool isDiscontinuityPending() const;
120     void finishHandleDiscontinuity(bool flushOnTimeChange);
121 
122     void notifyResumeCompleteIfNecessary();
123 
124     DISALLOW_EVIL_CONSTRUCTORS(Decoder);
125 };
126 
127 }  // namespace android
128 
129 #endif  // NUPLAYER_DECODER_H_
130