• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "aemu/base/files/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         HEVC = 4,
42     };
43 
44 public:
MediaSnapshotHelper(CodecType type)45     MediaSnapshotHelper(CodecType type) : mType(type) {}
46     ~MediaSnapshotHelper() = default;
47 
48 public:
49 public:
50     void savePacket(const uint8_t* compressedFrame, size_t len, uint64_t pts);
51 
52     void save(base::Stream* stream) const;
53 
54     void saveDecodedFrame(std::vector<uint8_t> data,
55                           int width = 0,
56                           int height = 0,
57                           uint64_t pts = 0,
58                           MediaSnapshotState::ColorAspects xcolor =
59                                   MediaSnapshotState::ColorAspects{}) {
60         mSnapshotState.saveDecodedFrame(std::move(data), width, height, pts,
61                                         xcolor);
62     }
63 
saveDecodedFrame(MediaSnapshotState::FrameInfo frame)64     void saveDecodedFrame(MediaSnapshotState::FrameInfo frame) {
65         mSnapshotState.saveDecodedFrame(std::move(frame));
66     }
67 
68     void saveDecodedFrame(std::vector<uint32_t> texture,
69                           int width = 0,
70                           int height = 0,
71                           uint64_t pts = 0,
72                           MediaSnapshotState::ColorAspects xcolor =
73                                   MediaSnapshotState::ColorAspects{}) {
74         mSnapshotState.saveDecodedFrame(texture, width, height, pts, xcolor);
75     }
76 
frontFrame()77     MediaSnapshotState::FrameInfo* frontFrame() {
78         return mSnapshotState.frontFrame();
79     }
80 
discardFrontFrame()81     void discardFrontFrame() { mSnapshotState.discardFrontFrame(); }
82 
83     void replay(std::function<void(uint8_t* data, size_t len, uint64_t pts)>
84                         oneShotDecode);
85 
86     void load(base::Stream* stream,
87               std::function<void(uint8_t* data, size_t len, uint64_t pts)>
88                       oneShotDecode);
89 
90 private:
91     CodecType mType = CodecType::H264;
92     mutable MediaSnapshotState mSnapshotState;
93 
94     void saveVPXPacket(const uint8_t* compressedFrame,
95                        size_t len,
96                        uint64_t pts);
97     void saveH264Packet(const uint8_t* compressedFrame,
98                         size_t len,
99                         uint64_t pts);
100     void saveHEVCPacket(const uint8_t* compressedFrame,
101                         size_t len,
102                         uint64_t pts);
103 
104 private:
105     unsigned int mOutputHeight = 0;
106     unsigned int mOutputWidth = 0;
107     unsigned int mSurfaceHeight = 0;
108     unsigned int mBPP = 0;
109     unsigned int mSurfaceWidth = 0;
110     unsigned int mLumaWidth = 0;
111     unsigned int mLumaHeight = 0;
112     unsigned int mChromaHeight = 0;
113     unsigned int mOutBufferSize = 0;
114 
115     unsigned int mColorPrimaries = 2;
116     unsigned int mColorRange = 0;
117     unsigned int mColorTransfer = 2;
118     unsigned int mColorSpace = 2;
119 
120 };  // MediaSnapshotHelper
121 
122 }  // namespace emulation
123 }  // namespace android
124