blob: 0c0e90cef5990b60386f8b83491fc214632eb9be [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
Chong Zhang7137ec72014-11-12 16:41:05 -08002 * Copyright 2014 The Android Open Source Project
Andreas Huberf9334412010-12-15 15:17:42 -08003 *
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_
Andreas Huberf9334412010-12-15 15:17:42 -080018#define NUPLAYER_DECODER_H_
19
20#include "NuPlayer.h"
21
Chong Zhang7137ec72014-11-12 16:41:05 -080022#include "NuPlayerDecoderBase.h"
Andreas Huberf9334412010-12-15 15:17:42 -080023
24namespace android {
25
Chong Zhang7137ec72014-11-12 16:41:05 -080026struct NuPlayer::Decoder : public DecoderBase {
Glenn Kasten11731182011-02-08 17:26:17 -080027 Decoder(const sp<AMessage> &notify,
Wei Jiac6cfd702014-11-11 16:33:20 -080028 const sp<Source> &source,
29 const sp<Renderer> &renderer = NULL,
Chong Zhang7137ec72014-11-12 16:41:05 -080030 const sp<NativeWindowWrapper> &nativeWindow = NULL,
31 const sp<CCDecoder> &ccDecoder = NULL);
Andreas Huberf9334412010-12-15 15:17:42 -080032
Chong Zhang7137ec72014-11-12 16:41:05 -080033 virtual void getStats(
34 int64_t *mNumFramesTotal,
35 int64_t *mNumFramesDropped) const;
Lajos Molnar1cd13982014-01-17 15:12:51 -080036
Andreas Huberf9334412010-12-15 15:17:42 -080037protected:
38 virtual ~Decoder();
39
40 virtual void onMessageReceived(const sp<AMessage> &msg);
41
Chong Zhang7137ec72014-11-12 16:41:05 -080042 virtual void onConfigure(const sp<AMessage> &format);
43 virtual void onSetRenderer(const sp<Renderer> &renderer);
44 virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers);
Chong Zhangf8d71772014-11-26 15:08:34 -080045 virtual void onResume(bool notifyComplete);
Chong Zhang66704af2015-03-03 19:32:35 -080046 virtual void onFlush();
Chong Zhang7137ec72014-11-12 16:41:05 -080047 virtual void onShutdown(bool notifyComplete);
48 virtual void doRequestBuffers();
Andreas Huberf9334412010-12-15 15:17:42 -080049
Wei Jiac6cfd702014-11-11 16:33:20 -080050private:
Chong Zhang7137ec72014-11-12 16:41:05 -080051 enum {
52 kWhatCodecNotify = 'cdcN',
53 kWhatRenderBuffer = 'rndr',
54 };
55
Glenn Kasten11731182011-02-08 17:26:17 -080056 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -080057
Wei Jiac6cfd702014-11-11 16:33:20 -080058 sp<Source> mSource;
59 sp<Renderer> mRenderer;
Chong Zhang7137ec72014-11-12 16:41:05 -080060 sp<CCDecoder> mCCDecoder;
Wei Jiac6cfd702014-11-11 16:33:20 -080061
Lajos Molnar1cd13982014-01-17 15:12:51 -080062 sp<AMessage> mInputFormat;
63 sp<AMessage> mOutputFormat;
64 sp<MediaCodec> mCodec;
Andreas Huber078cfcf2011-09-15 12:25:04 -070065 sp<ALooper> mCodecLooper;
Andreas Huberf9334412010-12-15 15:17:42 -080066
Wei Jia2245fc62014-10-02 15:12:25 -070067 List<sp<AMessage> > mPendingInputMessages;
68
Lajos Molnar1cd13982014-01-17 15:12:51 -080069 Vector<sp<ABuffer> > mInputBuffers;
70 Vector<sp<ABuffer> > mOutputBuffers;
Lajos Molnar87603c02014-08-20 19:25:30 -070071 Vector<sp<ABuffer> > mCSDsForCurrentFormat;
72 Vector<sp<ABuffer> > mCSDsToSubmit;
Lajos Molnar09524832014-07-17 14:29:51 -070073 Vector<bool> mInputBufferIsDequeued;
74 Vector<MediaBuffer *> mMediaBuffers;
Chong Zhang7137ec72014-11-12 16:41:05 -080075 Vector<size_t> mDequeuedInputBuffers;
Andreas Huberf9334412010-12-15 15:17:42 -080076
Wei Jiac6cfd702014-11-11 16:33:20 -080077 int64_t mSkipRenderingUntilMediaTimeUs;
Chong Zhang7137ec72014-11-12 16:41:05 -080078 int64_t mNumFramesTotal;
79 int64_t mNumFramesDropped;
80 bool mIsAudio;
81 bool mIsVideoAVC;
82 bool mIsSecure;
83 bool mFormatChangePending;
Chong Zhang66704af2015-03-03 19:32:35 -080084 bool mTimeChangePending;
Chong Zhang7137ec72014-11-12 16:41:05 -080085
Chong Zhang7137ec72014-11-12 16:41:05 -080086 bool mPaused;
Chong Zhangf8d71772014-11-26 15:08:34 -080087 bool mResumePending;
Chong Zhang7137ec72014-11-12 16:41:05 -080088 AString mComponentName;
Wei Jiac6cfd702014-11-11 16:33:20 -080089
Marco Nelissen421f47c2015-03-25 14:40:32 -070090 void handleError(int32_t err);
91 bool handleAnInputBuffer(size_t index);
92 bool handleAnOutputBuffer(
93 size_t index,
94 size_t offset,
95 size_t size,
96 int64_t timeUs,
97 int32_t flags);
98 void handleOutputFormatChange(const sp<AMessage> &format);
Andreas Huberf9334412010-12-15 15:17:42 -080099
Lajos Molnar09524832014-07-17 14:29:51 -0700100 void releaseAndResetMediaBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800101 void requestCodecNotification();
102 bool isStaleReply(const sp<AMessage> &msg);
103
Chong Zhang66704af2015-03-03 19:32:35 -0800104 void doFlush(bool notifyComplete);
Chong Zhang7137ec72014-11-12 16:41:05 -0800105 status_t fetchInputData(sp<AMessage> &reply);
106 bool onInputBufferFetched(const sp<AMessage> &msg);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800107 void onRenderBuffer(const sp<AMessage> &msg);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800108
Chong Zhang7137ec72014-11-12 16:41:05 -0800109 bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
Robert Shih6d0a94e2014-01-23 16:18:22 -0800110 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
Lajos Molnar87603c02014-08-20 19:25:30 -0700111 void rememberCodecSpecificData(const sp<AMessage> &format);
Chong Zhang66704af2015-03-03 19:32:35 -0800112 bool isDiscontinuityPending() const;
113 void finishHandleDiscontinuity(bool flushOnTimeChange);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800114
Chong Zhangf8d71772014-11-26 15:08:34 -0800115 void notifyResumeCompleteIfNecessary();
116
Andreas Huberf9334412010-12-15 15:17:42 -0800117 DISALLOW_EVIL_CONSTRUCTORS(Decoder);
118};
119
Andreas Huberf9334412010-12-15 15:17:42 -0800120} // namespace android
121
122#endif // NUPLAYER_DECODER_H_