blob: ceccb7a365cc9fe282d5dd71d8f2d1ed44fdbc7e [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,
Lajos Molnar1de1e252015-04-30 18:18:34 -070030 const sp<Surface> &surface = NULL,
Chong Zhang7137ec72014-11-12 16:41:05 -080031 const sp<CCDecoder> &ccDecoder = NULL);
Andreas Huberf9334412010-12-15 15:17:42 -080032
Praveen Chavane1e5d7a2015-05-19 19:09:48 -070033 virtual sp<AMessage> getStats() const;
Lajos Molnar1cd13982014-01-17 15:12:51 -080034
Andreas Huberf9334412010-12-15 15:17:42 -080035protected:
36 virtual ~Decoder();
37
38 virtual void onMessageReceived(const sp<AMessage> &msg);
39
Chong Zhang7137ec72014-11-12 16:41:05 -080040 virtual void onConfigure(const sp<AMessage> &format);
Ronghua Wu8db88132015-04-22 13:51:35 -070041 virtual void onSetParameters(const sp<AMessage> &params);
Chong Zhang7137ec72014-11-12 16:41:05 -080042 virtual void onSetRenderer(const sp<Renderer> &renderer);
43 virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers);
Chong Zhangf8d71772014-11-26 15:08:34 -080044 virtual void onResume(bool notifyComplete);
Chong Zhang66704af2015-03-03 19:32:35 -080045 virtual void onFlush();
Chong Zhang7137ec72014-11-12 16:41:05 -080046 virtual void onShutdown(bool notifyComplete);
Chong Zhang3b032b32015-04-17 15:49:06 -070047 virtual bool doRequestBuffers();
Andreas Huberf9334412010-12-15 15:17:42 -080048
Wei Jiac6cfd702014-11-11 16:33:20 -080049private:
Chong Zhang7137ec72014-11-12 16:41:05 -080050 enum {
51 kWhatCodecNotify = 'cdcN',
52 kWhatRenderBuffer = 'rndr',
53 };
54
Lajos Molnar1de1e252015-04-30 18:18:34 -070055 sp<Surface> mSurface;
Andreas Huberf9334412010-12-15 15:17:42 -080056
Wei Jiac6cfd702014-11-11 16:33:20 -080057 sp<Source> mSource;
58 sp<Renderer> mRenderer;
Chong Zhang7137ec72014-11-12 16:41:05 -080059 sp<CCDecoder> mCCDecoder;
Wei Jiac6cfd702014-11-11 16:33:20 -080060
Lajos Molnar1cd13982014-01-17 15:12:51 -080061 sp<AMessage> mInputFormat;
62 sp<AMessage> mOutputFormat;
63 sp<MediaCodec> mCodec;
Andreas Huber078cfcf2011-09-15 12:25:04 -070064 sp<ALooper> mCodecLooper;
Andreas Huberf9334412010-12-15 15:17:42 -080065
Wei Jia2245fc62014-10-02 15:12:25 -070066 List<sp<AMessage> > mPendingInputMessages;
67
Lajos Molnar1cd13982014-01-17 15:12:51 -080068 Vector<sp<ABuffer> > mInputBuffers;
69 Vector<sp<ABuffer> > mOutputBuffers;
Lajos Molnar87603c02014-08-20 19:25:30 -070070 Vector<sp<ABuffer> > mCSDsForCurrentFormat;
71 Vector<sp<ABuffer> > mCSDsToSubmit;
Lajos Molnar09524832014-07-17 14:29:51 -070072 Vector<bool> mInputBufferIsDequeued;
73 Vector<MediaBuffer *> mMediaBuffers;
Chong Zhang7137ec72014-11-12 16:41:05 -080074 Vector<size_t> mDequeuedInputBuffers;
Andreas Huberf9334412010-12-15 15:17:42 -080075
Wei Jiac6cfd702014-11-11 16:33:20 -080076 int64_t mSkipRenderingUntilMediaTimeUs;
Chong Zhang7137ec72014-11-12 16:41:05 -080077 int64_t mNumFramesTotal;
Praveen Chavane1e5d7a2015-05-19 19:09:48 -070078 int64_t mNumInputFramesDropped;
79 int64_t mNumOutputFramesDropped;
80 int32_t mVideoWidth;
81 int32_t mVideoHeight;
Chong Zhang7137ec72014-11-12 16:41:05 -080082 bool mIsAudio;
83 bool mIsVideoAVC;
84 bool mIsSecure;
85 bool mFormatChangePending;
Chong Zhang66704af2015-03-03 19:32:35 -080086 bool mTimeChangePending;
Chong Zhang7137ec72014-11-12 16:41:05 -080087
Chong Zhang7137ec72014-11-12 16:41:05 -080088 bool mPaused;
Chong Zhangf8d71772014-11-26 15:08:34 -080089 bool mResumePending;
Chong Zhang7137ec72014-11-12 16:41:05 -080090 AString mComponentName;
Wei Jiac6cfd702014-11-11 16:33:20 -080091
Marco Nelissen421f47c2015-03-25 14:40:32 -070092 void handleError(int32_t err);
93 bool handleAnInputBuffer(size_t index);
94 bool handleAnOutputBuffer(
95 size_t index,
96 size_t offset,
97 size_t size,
98 int64_t timeUs,
99 int32_t flags);
100 void handleOutputFormatChange(const sp<AMessage> &format);
Andreas Huberf9334412010-12-15 15:17:42 -0800101
Lajos Molnar09524832014-07-17 14:29:51 -0700102 void releaseAndResetMediaBuffers();
Lajos Molnar1cd13982014-01-17 15:12:51 -0800103 void requestCodecNotification();
104 bool isStaleReply(const sp<AMessage> &msg);
105
Chong Zhang66704af2015-03-03 19:32:35 -0800106 void doFlush(bool notifyComplete);
Chong Zhang7137ec72014-11-12 16:41:05 -0800107 status_t fetchInputData(sp<AMessage> &reply);
108 bool onInputBufferFetched(const sp<AMessage> &msg);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800109 void onRenderBuffer(const sp<AMessage> &msg);
Lajos Molnar1cd13982014-01-17 15:12:51 -0800110
Chong Zhang7137ec72014-11-12 16:41:05 -0800111 bool supportsSeamlessFormatChange(const sp<AMessage> &to) const;
Robert Shih6d0a94e2014-01-23 16:18:22 -0800112 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const;
Lajos Molnar87603c02014-08-20 19:25:30 -0700113 void rememberCodecSpecificData(const sp<AMessage> &format);
Chong Zhang66704af2015-03-03 19:32:35 -0800114 bool isDiscontinuityPending() const;
115 void finishHandleDiscontinuity(bool flushOnTimeChange);
Robert Shih6d0a94e2014-01-23 16:18:22 -0800116
Chong Zhangf8d71772014-11-26 15:08:34 -0800117 void notifyResumeCompleteIfNecessary();
118
Andreas Huberf9334412010-12-15 15:17:42 -0800119 DISALLOW_EVIL_CONSTRUCTORS(Decoder);
120};
121
Andreas Huberf9334412010-12-15 15:17:42 -0800122} // namespace android
123
124#endif // NUPLAYER_DECODER_H_