blob: 9e8167d3b1fd1e279c91f2db6f4015ffb696011f [file] [log] [blame]
Ajit Khare73cfaf42013-01-07 23:28:47 -08001/*
2 * Copyright (C) 2010 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 DASHPLAYER_DECODER_H_
18
19#define DASHPLAYER_DECODER_H_
20
21#include "DashPlayerRenderer.h"
22#include "DashPlayer.h"
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053023#include <media/stagefright/foundation/AHandler.h>
Ajit Khare73cfaf42013-01-07 23:28:47 -080024
25namespace android {
26
27struct ABuffer;
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053028struct MediaCodec;
Ajit Khare73cfaf42013-01-07 23:28:47 -080029
30struct DashPlayer::Decoder : public AHandler {
31 Decoder(const sp<AMessage> &notify,
Manikanta Sivapala672cd8f2015-08-05 19:12:15 +053032 const sp<Surface> &nativeWindow = NULL);
Ajit Khare73cfaf42013-01-07 23:28:47 -080033
34 void configure(const sp<MetaData> &meta);
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053035 void init();
Ajit Khare73cfaf42013-01-07 23:28:47 -080036
37 void signalFlush();
38 void signalResume();
39 void initiateShutdown();
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053040
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053041
42 enum {
43 kWhatFillThisBuffer = 'flTB',
44 kWhatDrainThisBuffer = 'drTB',
45 kWhatOutputFormatChanged = 'fmtC',
46 kWhatFlushCompleted = 'flsC',
47 kWhatShutdownCompleted = 'shDC',
48 kWhatEOS = 'eos ',
49 kWhatError = 'err ',
50 };
Ajit Khare73cfaf42013-01-07 23:28:47 -080051
52protected:
53 virtual ~Decoder();
54
55 virtual void onMessageReceived(const sp<AMessage> &msg);
56
57private:
58 enum {
59 kWhatCodecNotify = 'cdcN',
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053060 kWhatConfigure = 'conf',
61 kWhatInputBufferFilled = 'inpF',
62 kWhatRenderBuffer = 'rndr',
63 kWhatFlush = 'flus',
64 kWhatShutdown = 'shuD',
Ajit Khare73cfaf42013-01-07 23:28:47 -080065 };
66
67 sp<AMessage> mNotify;
Manikanta Sivapala672cd8f2015-08-05 19:12:15 +053068 sp<Surface> mNativeWindow;
Ajit Khare73cfaf42013-01-07 23:28:47 -080069
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053070 sp<AMessage> mInputFormat;
71 sp<AMessage> mOutputFormat;
72 sp<MediaCodec> mCodec;
Ajit Khare73cfaf42013-01-07 23:28:47 -080073 sp<ALooper> mCodecLooper;
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053074 sp<ALooper> mDecoderLooper;
Ajit Khare73cfaf42013-01-07 23:28:47 -080075
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053076 Vector<sp<ABuffer> > mInputBuffers;
77 Vector<sp<ABuffer> > mOutputBuffers;
78
79 void handleError(int32_t err);
80 bool handleAnInputBuffer();
81 bool handleAnOutputBuffer();
82
83 void requestCodecNotification();
84 bool isStaleReply(const sp<AMessage> &msg);
85
Manikanta Sivapala29760d62015-08-05 14:37:03 +053086 int mLogLevel;
Ajit Khare73cfaf42013-01-07 23:28:47 -080087
88 sp<AMessage> makeFormat(const sp<MetaData> &meta);
89
Mahesh Lanka4d0ff4e2014-07-21 22:35:33 +053090 void onConfigure(const sp<AMessage> &format);
91 void onFlush();
92 void onInputBufferFilled(const sp<AMessage> &msg);
93 void onRenderBuffer(const sp<AMessage> &msg);
94 void onShutdown();
95
96 int32_t mBufferGeneration;
97 AString mComponentName;
98
Ajit Khare73cfaf42013-01-07 23:28:47 -080099
100 DISALLOW_EVIL_CONSTRUCTORS(Decoder);
101};
102
103} // namespace android
104
105#endif // DASHPLAYER_DECODER_H_