1 /* 2 * Copyright (C) 2017 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 _NATIVE_MEDIA_SOURCE_H_ 18 #define _NATIVE_MEDIA_SOURCE_H_ 19 20 #include <stdlib.h> 21 #include <stdint.h> 22 #include <memory> 23 #include <string> 24 25 #include <android/native_window_jni.h> 26 27 #include "media/NdkMediaFormat.h" 28 #include "media/NdkMediaExtractor.h" 29 #include "media/NdkMediaCodec.h" 30 #include "media/NdkMediaMuxer.h" 31 32 #include "native_media_utils.h" 33 using Utils::Thread; 34 using Utils::Status; 35 36 class Source { 37 public: Source(int32_t w,int32_t h,int32_t colorFormat,float fps,bool looping)38 Source(int32_t w, int32_t h, int32_t colorFormat, float fps, bool looping) 39 : mWidth(w), 40 mHeight(h), 41 mColorFormat(colorFormat), 42 mFps(fps), 43 mLooping(looping), 44 mBufListener(nullptr) { 45 } 46 virtual ~Source() = default; 47 48 class Listener { 49 public: 50 virtual void onBufferAvailable( 51 uint8_t *buffer, int32_t size, int64_t timeStampUs, uint32_t flags) = 0; 52 virtual ~Listener() = default; 53 }; 54 virtual Status prepare(std::shared_ptr<Listener> l, std::shared_ptr<ANativeWindow> n) = 0; 55 virtual Status start() = 0; 56 virtual Status stop() = 0; 57 58 protected: 59 int32_t mWidth; 60 int32_t mHeight; 61 int32_t mColorFormat; 62 float mFps; 63 bool mLooping; 64 std::shared_ptr<Listener> mBufListener; 65 std::shared_ptr<ANativeWindow> mSurface; 66 }; 67 68 std::shared_ptr<Source> createDecoderSource( 69 int32_t w, int32_t h, int32_t colorFormat, float fps, bool looping, 70 bool regulateFeedingRate, /* WA for dynamic settings */ 71 int sourceFileFd, off64_t sourceFileOffset, off64_t sourceFileSize); 72 73 #endif // _NATIVE_MEDIA_SOURCE_H_ 74