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 #include "aemu/base/files/Stream.h" 17 18 #include <stddef.h> 19 #include <list> 20 #include <vector> 21 22 namespace android { 23 namespace emulation { 24 25 class MediaSnapshotHelper; 26 27 class MediaSnapshotState { 28 public: 29 struct ColorAspects { 30 unsigned int primaries; 31 unsigned int range; 32 unsigned int transfer; 33 unsigned int space; 34 }; 35 36 struct PacketInfo { 37 std::vector<uint8_t> data; 38 uint64_t pts; 39 }; 40 41 struct FrameInfo { 42 std::vector<uint8_t> data; 43 std::vector<uint32_t> texture; 44 int width; 45 int height; 46 uint64_t pts; 47 ColorAspects color; 48 }; 49 50 bool savePacket(std::vector<uint8_t> data, uint64_t pts = 0); saveSps(std::vector<uint8_t> xsps)51 void saveSps(std::vector<uint8_t> xsps) { sps = std::move(xsps); } savePps(std::vector<uint8_t> xpps)52 void savePps(std::vector<uint8_t> xpps) { pps = std::move(xpps); } 53 54 void saveDecodedFrame(std::vector<uint8_t> data, 55 int width = 0, 56 int height = 0, 57 uint64_t pts = 0, 58 ColorAspects xcolor = ColorAspects{}); 59 60 void saveDecodedFrame(std::vector<uint32_t> texture, 61 int width = 0, 62 int height = 0, 63 uint64_t pts = 0, 64 ColorAspects xcolor = ColorAspects{}); 65 saveDecodedFrame(FrameInfo frame)66 void saveDecodedFrame(FrameInfo frame) { 67 savedFrames.push_back(std::move(frame)); 68 } 69 70 void save(base::Stream* stream) const; 71 void load(base::Stream* stream); 72 frontFrame()73 FrameInfo* frontFrame() { 74 if (savedFrames.empty()) { 75 return nullptr; 76 } 77 return &(savedFrames.front()); 78 } 79 discardFrontFrame()80 void discardFrontFrame() { 81 if (!savedFrames.empty()) { 82 savedFrames.pop_front(); 83 } 84 } 85 86 friend MediaSnapshotHelper; 87 88 private: 89 std::vector<uint8_t> sps; // sps NALU 90 std::vector<uint8_t> pps; // pps NALU 91 std::vector<PacketInfo> savedPackets; 92 FrameInfo savedDecodedFrame; // only one or nothing 93 std::list<FrameInfo> savedFrames; 94 95 private: 96 bool savePacket(const uint8_t* frame, size_t size, uint64_t pts = 0); 97 98 // void saveVec(base::Stream* stream, const std::vector<uint8_t>& vec) 99 // const; 100 101 void saveFrameInfo(base::Stream* stream, const FrameInfo& frame) const; 102 103 void savePacketInfo(base::Stream* stream, const PacketInfo& pkt) const; 104 void saveColor(base::Stream* stream, const ColorAspects& color) const; 105 106 void loadFrameInfo(base::Stream* stream, FrameInfo& frame); 107 108 void loadPacketInfo(base::Stream* stream, PacketInfo& pkt); 109 110 void loadColor(base::Stream* stream, ColorAspects& color) const; 111 112 // void loadVec(base::Stream* stream, std::vector<uint8_t>& vec); 113 }; 114 115 } // namespace emulation 116 } // namespace android 117