1 // Copyright (C) 2019 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include "base/Stream.h" 18 #include "host-common/MediaSnapshotState.h" 19 20 #include <cstdint> 21 #include <functional> 22 #include <list> 23 #include <mutex> 24 #include <string> 25 #include <vector> 26 27 #include <stdio.h> 28 #include <string.h> 29 30 #include <stddef.h> 31 32 namespace android { 33 namespace emulation { 34 35 class MediaSnapshotHelper { 36 public: 37 enum class CodecType { 38 H264 = 1, 39 VP8 = 2, 40 VP9 = 3, 41 }; 42 43 public: MediaSnapshotHelper(CodecType type)44 MediaSnapshotHelper(CodecType type) : mType(type) {} 45 ~MediaSnapshotHelper() = default; 46 47 public: 48 public: 49 void savePacket(const uint8_t* compressedFrame, size_t len, uint64_t pts); 50 51 void save(base::Stream* stream) const; 52 53 void saveDecodedFrame(std::vector<uint8_t> data, 54 int width = 0, 55 int height = 0, 56 uint64_t pts = 0, 57 MediaSnapshotState::ColorAspects xcolor = 58 MediaSnapshotState::ColorAspects{}) { 59 mSnapshotState.saveDecodedFrame(std::move(data), width, height, pts, 60 xcolor); 61 } 62 saveDecodedFrame(MediaSnapshotState::FrameInfo frame)63 void saveDecodedFrame(MediaSnapshotState::FrameInfo frame) { 64 mSnapshotState.saveDecodedFrame(std::move(frame)); 65 } 66 67 void saveDecodedFrame(std::vector<uint32_t> texture, 68 int width = 0, 69 int height = 0, 70 uint64_t pts = 0, 71 MediaSnapshotState::ColorAspects xcolor = 72 MediaSnapshotState::ColorAspects{}) { 73 mSnapshotState.saveDecodedFrame(texture, width, height, pts, xcolor); 74 } 75 frontFrame()76 MediaSnapshotState::FrameInfo* frontFrame() { 77 return mSnapshotState.frontFrame(); 78 } 79 discardFrontFrame()80 void discardFrontFrame() { mSnapshotState.discardFrontFrame(); } 81 82 void replay(std::function<void(uint8_t* data, size_t len, uint64_t pts)> 83 oneShotDecode); 84 85 void load(base::Stream* stream, 86 std::function<void(uint8_t* data, size_t len, uint64_t pts)> 87 oneShotDecode); 88 89 private: 90 CodecType mType = CodecType::H264; 91 mutable MediaSnapshotState mSnapshotState; 92 93 void saveVPXPacket(const uint8_t* compressedFrame, 94 size_t len, 95 uint64_t pts); 96 void saveH264Packet(const uint8_t* compressedFrame, 97 size_t len, 98 uint64_t pts); 99 100 private: 101 unsigned int mOutputHeight = 0; 102 unsigned int mOutputWidth = 0; 103 unsigned int mSurfaceHeight = 0; 104 unsigned int mBPP = 0; 105 unsigned int mSurfaceWidth = 0; 106 unsigned int mLumaWidth = 0; 107 unsigned int mLumaHeight = 0; 108 unsigned int mChromaHeight = 0; 109 unsigned int mOutBufferSize = 0; 110 111 unsigned int mColorPrimaries = 2; 112 unsigned int mColorRange = 0; 113 unsigned int mColorTransfer = 2; 114 unsigned int mColorSpace = 2; 115 116 }; // MediaSnapshotHelper 117 118 } // namespace emulation 119 } // namespace android 120