Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 1 | /* |
| 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 NUPLAYER_DECODER_BASE_H_ |
| 18 | |
| 19 | #define NUPLAYER_DECODER_BASE_H_ |
| 20 | |
| 21 | #include "NuPlayer.h" |
| 22 | |
| 23 | #include <media/stagefright/foundation/AHandler.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | struct ABuffer; |
| 28 | struct MediaCodec; |
Lajos Molnar | ee4e1b1 | 2015-04-17 13:46:19 -0700 | [diff] [blame] | 29 | class MediaBuffer; |
Lajos Molnar | a81c622 | 2015-07-10 19:17:45 -0700 | [diff] [blame] | 30 | class Surface; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 31 | |
| 32 | struct NuPlayer::DecoderBase : public AHandler { |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame^] | 33 | explicit DecoderBase(const sp<AMessage> ¬ify); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 34 | |
| 35 | void configure(const sp<AMessage> &format); |
| 36 | void init(); |
Ronghua Wu | 8db8813 | 2015-04-22 13:51:35 -0700 | [diff] [blame] | 37 | void setParameters(const sp<AMessage> ¶ms); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 38 | |
Wei Jia | 3bc6670 | 2015-11-18 15:45:06 -0800 | [diff] [blame] | 39 | // Synchronous call to ensure decoder will not request or send out data. |
| 40 | void pause(); |
| 41 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 42 | void setRenderer(const sp<Renderer> &renderer); |
Lajos Molnar | a81c622 | 2015-07-10 19:17:45 -0700 | [diff] [blame] | 43 | virtual status_t setVideoSurface(const sp<Surface> &) { return INVALID_OPERATION; } |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 44 | |
| 45 | status_t getInputBuffers(Vector<sp<ABuffer> > *dstBuffers) const; |
| 46 | void signalFlush(); |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 47 | void signalResume(bool notifyComplete); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 48 | void initiateShutdown(); |
| 49 | |
Praveen Chavan | e1e5d7a | 2015-05-19 19:09:48 -0700 | [diff] [blame] | 50 | virtual sp<AMessage> getStats() const { |
| 51 | return mStats; |
| 52 | } |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 53 | |
| 54 | enum { |
| 55 | kWhatInputDiscontinuity = 'inDi', |
| 56 | kWhatVideoSizeChanged = 'viSC', |
| 57 | kWhatFlushCompleted = 'flsC', |
| 58 | kWhatShutdownCompleted = 'shDC', |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 59 | kWhatResumeCompleted = 'resC', |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 60 | kWhatEOS = 'eos ', |
| 61 | kWhatError = 'err ', |
| 62 | }; |
| 63 | |
| 64 | protected: |
| 65 | |
| 66 | virtual ~DecoderBase(); |
| 67 | |
| 68 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 69 | |
| 70 | virtual void onConfigure(const sp<AMessage> &format) = 0; |
Ronghua Wu | 8db8813 | 2015-04-22 13:51:35 -0700 | [diff] [blame] | 71 | virtual void onSetParameters(const sp<AMessage> ¶ms) = 0; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 72 | virtual void onSetRenderer(const sp<Renderer> &renderer) = 0; |
| 73 | virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers) = 0; |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 74 | virtual void onResume(bool notifyComplete) = 0; |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 75 | virtual void onFlush() = 0; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 76 | virtual void onShutdown(bool notifyComplete) = 0; |
| 77 | |
| 78 | void onRequestInputBuffers(); |
Chong Zhang | 3b032b3 | 2015-04-17 15:49:06 -0700 | [diff] [blame] | 79 | virtual bool doRequestBuffers() = 0; |
Andy Hung | 202bce1 | 2014-12-03 11:47:36 -0800 | [diff] [blame] | 80 | virtual void handleError(int32_t err); |
| 81 | |
| 82 | sp<AMessage> mNotify; |
| 83 | int32_t mBufferGeneration; |
Wei Jia | 3bc6670 | 2015-11-18 15:45:06 -0800 | [diff] [blame] | 84 | bool mPaused; |
Praveen Chavan | e1e5d7a | 2015-05-19 19:09:48 -0700 | [diff] [blame] | 85 | sp<AMessage> mStats; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | enum { |
| 89 | kWhatConfigure = 'conf', |
Ronghua Wu | 8db8813 | 2015-04-22 13:51:35 -0700 | [diff] [blame] | 90 | kWhatSetParameters = 'setP', |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 91 | kWhatSetRenderer = 'setR', |
Wei Jia | 3bc6670 | 2015-11-18 15:45:06 -0800 | [diff] [blame] | 92 | kWhatPause = 'paus', |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 93 | kWhatGetInputBuffers = 'gInB', |
| 94 | kWhatRequestInputBuffers = 'reqB', |
| 95 | kWhatFlush = 'flus', |
| 96 | kWhatShutdown = 'shuD', |
| 97 | }; |
| 98 | |
| 99 | sp<ALooper> mDecoderLooper; |
| 100 | bool mRequestInputBuffersPending; |
| 101 | |
| 102 | DISALLOW_EVIL_CONSTRUCTORS(DecoderBase); |
| 103 | }; |
| 104 | |
| 105 | } // namespace android |
| 106 | |
| 107 | #endif // NUPLAYER_DECODER_BASE_H_ |