blob: 4a52b0c06a9047a88d2ddc2f274831f8510baeaf [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
Wonsik Kim7e34bf52016-08-23 00:09:18 +090026class MediaCodecBuffer;
27
Chong Zhang7137ec72014-11-12 16:41:05 -080028struct NuPlayer::Decoder : public DecoderBase {
Glenn Kasten11731182011-02-08 17:26:17 -080029 Decoder(const sp<AMessage> &notify,
Wei Jiac6cfd702014-11-11 16:33:20 -080030 const sp<Source> &source,
Ronghua Wu68845c12015-07-21 09:50:48 -070031 pid_t pid,
Wei Jiaf2ae3e12016-10-27 17:10:59 -070032 uid_t uid,
Wei Jiac6cfd702014-11-11 16:33:20 -080033 const sp<Renderer> &renderer = NULL,
Lajos Molnar1de1e252015-04-30 18:18:34 -070034 const sp<Surface> &surface = NULL,
Chong Zhang7137ec72014-11-12 16:41:05 -080035 const sp<CCDecoder> &ccDecoder = NULL);
Andreas Huberf9334412010-12-15 15:17:42 -080036
Ray Essick83f56b02019-06-23 15:13:46 -070037 virtual sp<AMessage> getStats();
Lajos Molnar1cd13982014-01-17 15:12:51 -080038
Lajos Molnara81c6222015-07-10 19:17:45 -070039 // sets the output surface of video decoders.
40 virtual status_t setVideoSurface(const sp<Surface> &surface);
41
Hassan Shojaniacefac142017-02-06 21:02:02 -080042 virtual status_t releaseCrypto();
43
Andreas Huberf9334412010-12-15 15:17:42 -080044protected:
45 virtual ~Decoder();
46
47 virtual void onMessageReceived(const sp<AMessage> &msg);
48
Chong Zhang7137ec72014-11-12 16:41:05 -080049 virtual void onConfigure(const sp<AMessage> &format);
Ronghua Wu8db88132015-04-22 13:51:35 -070050 virtual void onSetParameters(const sp<AMessage> &params);
Chong Zhang7137ec72014-11-12 16:41:05 -080051 virtual void onSetRenderer(const sp<Renderer> &renderer);
Chong Zhangf8d71772014-11-26 15:08:34 -080052 virtual void onResume(bool notifyComplete);
Chong Zhang66704af2015-03-03 19:32:35 -080053 virtual void onFlush();
Chong Zhang7137ec72014-11-12 16:41:05 -080054 virtual void onShutdown(bool notifyComplete);
Chong Zhang3b032b32015-04-17 15:49:06 -070055 virtual bool doRequestBuffers();
Andreas Huberf9334412010-12-15 15:17:42 -080056
Wei Jiac6cfd702014-11-11 16:33:20 -080057private:
Chong Zhang7137ec72014-11-12 16:41:05 -080058 enum {
59 kWhatCodecNotify = 'cdcN',
60 kWhatRenderBuffer = 'rndr',
Wei Jia9a3101b2016-11-08 14:34:24 -080061 kWhatSetVideoSurface = 'sSur',
Hassan Shojaniacefac142017-02-06 21:02:02 -080062 kWhatAudioOutputFormatChanged = 'aofc',
63 kWhatDrmReleaseCrypto = 'rDrm',
Chong Zhang7137ec72014-11-12 16:41:05 -080064 };
65
Praveen Chavanbbaa1442016-04-08 13:33:49 -070066 enum {
67 kMaxNumVideoTemporalLayers = 32,
68 };
69
Lajos Molnar1de1e252015-04-30 18:18:34 -070070 sp<Surface> mSurface;
Andreas Huberf9334412010-12-15 15:17:42 -080071
Wei Jiac6cfd702014-11-11 16:33:20 -080072 sp<Source> mSource;
73 sp<Renderer> mRenderer;
Chong Zhang7137ec72014-11-12 16:41:05 -080074 sp<CCDecoder> mCCDecoder;
Wei Jiac6cfd702014-11-11 16:33:20 -080075
Lajos Molnar1cd13982014-01-17 15:12:51 -080076 sp<AMessage> mInputFormat;
77 sp<AMessage> mOutputFormat;
78 sp<MediaCodec> mCodec;
Andreas Huber078cfcf2011-09-15 12:25:04 -070079 sp<ALooper> mCodecLooper;
Andreas Huberf9334412010-12-15 15:17:42 -080080
Wei Jia2245fc62014-10-02 15:12:25 -070081 List<sp<AMessage> > mPendingInputMessages;
82
Wonsik Kim7e34bf52016-08-23 00:09:18 +090083 Vector<sp<MediaCodecBuffer> > mInputBuffers;
84 Vector<sp<MediaCodecBuffer> > mOutputBuffers;
Lajos Molnar87603c02014-08-20 19:25:30 -070085 Vector<sp<ABuffer> > mCSDsForCurrentFormat;
86 Vector<sp<ABuffer> > mCSDsToSubmit;
Lajos Molnar09524832014-07-17 14:29:51 -070087 Vector<bool> mInputBufferIsDequeued;
88 Vector<MediaBuffer *> mMediaBuffers;
Chong Zhang7137ec72014-11-12 16:41:05 -080089 Vector<size_t> mDequeuedInputBuffers;
Andreas Huberf9334412010-12-15 15:17:42 -080090
Ronghua Wu68845c12015-07-21 09:50:48 -070091 const pid_t mPid;
Wei Jiaf2ae3e12016-10-27 17:10:59 -070092 const uid_t mUid;
Wei Jiac6cfd702014-11-11 16:33:20 -080093 int64_t mSkipRenderingUntilMediaTimeUs;
Chong Zhang7137ec72014-11-12 16:41:05 -080094 int64_t mNumFramesTotal;
Praveen Chavane1e5d7a2015-05-19 19:09:48 -070095 int64_t mNumInputFramesDropped;
96 int64_t mNumOutputFramesDropped;
97 int32_t mVideoWidth;
98 int32_t mVideoHeight;
Chong Zhang7137ec72014-11-12 16:41:05 -080099 bool mIsAudio;
100 bool mIsVideoAVC;
101 bool mIsSecure;
Hassan Shojania62dec952017-05-18 10:45:27 -0700102 bool mIsEncrypted;
103 bool mIsEncryptedObservedEarlier;
Chong Zhang7137ec72014-11-12 16:41:05 -0800104 bool mFormatChangePending;
Chong Zhang66704af2015-03-03 19:32:35 -0800105 bool mTimeChangePending;
Praveen Chavanbbaa1442016-04-08 13:33:49 -0700106 float mFrameRateTotal;
107 float mPlaybackSpeed;
108 int32_t mNumVideoTemporalLayerTotal;
109 int32_t mNumVideoTemporalLayerAllowed;
110 int32_t mCurrentMaxVideoTemporalLayerId;
111 float mVideoTemporalLayerAggregateFps[kMaxNumVideoTemporalLayers];
Chong Zhang7137ec72014-11-12 16:41:05 -0800112
Chong Zhangf8d71772014-11-26 15:08:34 -0800113 bool mResumePending;
Chong Zhang7137ec72014-11-12 16:41:05 -0800114 AString mComponentName;
Wei Jiac6cfd702014-11-11 16:33:20 -0800115
Marco Nelissen421f47c2015-03-25 14:40:32 -0700116 void handleError(int32_t err);
117 bool handleAnInputBuffer(size_t index);
118 bool handleAnOutputBuffer(
119 size_t index,
120 size_t offset,
121 size_t size,
122 int64_t timeUs,
123 int32_t flags);
124 void handleOutputFormatChange(const sp<AMessage> &format);
Andreas Huberf9334412010-12-15 15:17:42 -0800125
Lajos Molnar09524832014-07-17 14:29:51 -0700126 void releaseAndResetMediaBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800127 void requestCodecNotification();
128 bool isStaleReply(const sp<AMessage> &msg);
129
Chong Zhang66704af2015-03-03 19:32:35 -0800130 void doFlush(bool notifyComplete);
Chong Zhang7137ec72014-11-12 16:41:05 -0800131 status_t fetchInputData(sp<AMessage> &reply);
132 bool onInputBufferFetched(const sp<AMessage> &msg);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800133 void onRenderBuffer(const sp<AMessage> &msg);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800134
Chong Zhang7137ec72014-11-12 16:41:05 -0800135 bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
Robert Shih6d0a94e2014-01-23 16:18:22 -0800136 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
Lajos Molnar87603c02014-08-20 19:25:30 -0700137 void rememberCodecSpecificData(const sp<AMessage> &format);
Chong Zhang66704af2015-03-03 19:32:35 -0800138 bool isDiscontinuityPending() const;
139 void finishHandleDiscontinuity(bool flushOnTimeChange);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800140
Chong Zhangf8d71772014-11-26 15:08:34 -0800141 void notifyResumeCompleteIfNecessary();
142
Hassan Shojaniacefac142017-02-06 21:02:02 -0800143 void onReleaseCrypto(const sp<AMessage>& msg);
144
Andreas Huberf9334412010-12-15 15:17:42 -0800145 DISALLOW_EVIL_CONSTRUCTORS(Decoder);
146};
147
Andreas Huberf9334412010-12-15 15:17:42 -0800148} // namespace android
149
150#endif // NUPLAYER_DECODER_H_