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 { |
Andy Hung | 202bce1 | 2014-12-03 11:47:36 -0800 | [diff] [blame] | 33 | 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 | |
| 39 | void setRenderer(const sp<Renderer> &renderer); |
Lajos Molnar | a81c622 | 2015-07-10 19:17:45 -0700 | [diff] [blame^] | 40 | virtual status_t setVideoSurface(const sp<Surface> &) { return INVALID_OPERATION; } |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 41 | |
| 42 | status_t getInputBuffers(Vector<sp<ABuffer> > *dstBuffers) const; |
| 43 | void signalFlush(); |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 44 | void signalResume(bool notifyComplete); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 45 | void initiateShutdown(); |
| 46 | |
Praveen Chavan | e1e5d7a | 2015-05-19 19:09:48 -0700 | [diff] [blame] | 47 | virtual sp<AMessage> getStats() const { |
| 48 | return mStats; |
| 49 | } |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 50 | |
| 51 | enum { |
| 52 | kWhatInputDiscontinuity = 'inDi', |
| 53 | kWhatVideoSizeChanged = 'viSC', |
| 54 | kWhatFlushCompleted = 'flsC', |
| 55 | kWhatShutdownCompleted = 'shDC', |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 56 | kWhatResumeCompleted = 'resC', |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 57 | kWhatEOS = 'eos ', |
| 58 | kWhatError = 'err ', |
| 59 | }; |
| 60 | |
| 61 | protected: |
| 62 | |
| 63 | virtual ~DecoderBase(); |
| 64 | |
| 65 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 66 | |
| 67 | virtual void onConfigure(const sp<AMessage> &format) = 0; |
Ronghua Wu | 8db8813 | 2015-04-22 13:51:35 -0700 | [diff] [blame] | 68 | virtual void onSetParameters(const sp<AMessage> ¶ms) = 0; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 69 | virtual void onSetRenderer(const sp<Renderer> &renderer) = 0; |
| 70 | virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers) = 0; |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 71 | virtual void onResume(bool notifyComplete) = 0; |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 72 | virtual void onFlush() = 0; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 73 | virtual void onShutdown(bool notifyComplete) = 0; |
| 74 | |
| 75 | void onRequestInputBuffers(); |
Chong Zhang | 3b032b3 | 2015-04-17 15:49:06 -0700 | [diff] [blame] | 76 | virtual bool doRequestBuffers() = 0; |
Andy Hung | 202bce1 | 2014-12-03 11:47:36 -0800 | [diff] [blame] | 77 | virtual void handleError(int32_t err); |
| 78 | |
| 79 | sp<AMessage> mNotify; |
| 80 | int32_t mBufferGeneration; |
Praveen Chavan | e1e5d7a | 2015-05-19 19:09:48 -0700 | [diff] [blame] | 81 | sp<AMessage> mStats; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | enum { |
| 85 | kWhatConfigure = 'conf', |
Ronghua Wu | 8db8813 | 2015-04-22 13:51:35 -0700 | [diff] [blame] | 86 | kWhatSetParameters = 'setP', |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 87 | kWhatSetRenderer = 'setR', |
| 88 | kWhatGetInputBuffers = 'gInB', |
| 89 | kWhatRequestInputBuffers = 'reqB', |
| 90 | kWhatFlush = 'flus', |
| 91 | kWhatShutdown = 'shuD', |
| 92 | }; |
| 93 | |
| 94 | sp<ALooper> mDecoderLooper; |
| 95 | bool mRequestInputBuffersPending; |
| 96 | |
| 97 | DISALLOW_EVIL_CONSTRUCTORS(DecoderBase); |
| 98 | }; |
| 99 | |
| 100 | } // namespace android |
| 101 | |
| 102 | #endif // NUPLAYER_DECODER_BASE_H_ |