• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2020 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 "host-common/GoldfishMediaDefs.h"
18 #include "host-common/H264NaluParser.h"
19 #include "host-common/MediaCodec.h"
20 #include "host-common/MediaH264DecoderFfmpeg.h"
21 #include "host-common/MediaH264DecoderVideoToolBox.h"
22 
23 #include <VideoToolbox/VideoToolbox.h>
24 
25 #include <cstdint>
26 #include <string>
27 #include <vector>
28 
29 #include <stdio.h>
30 #include <string.h>
31 
32 #include <stddef.h>
33 
34 namespace android {
35 namespace emulation {
36 
37 class MediaH264DecoderVideoToolBoxProxy : public MediaH264DecoderPlugin {
38 public:
39 
40 
41     virtual MediaH264DecoderPlugin* clone() override;
42     virtual void destroyH264Context() override;
43     virtual void decodeFrame(void* ptr) override;
44     virtual void flush(void* ptr) override;
45     virtual void initH264Context(void* ptr) override;
46     virtual void reset(void* ptr) override;
47     virtual void getImage(void* ptr) override;
48 
49     virtual void save(base::Stream* stream) const override;
50     virtual bool load(base::Stream* stream) override;
51 
type()52     virtual int type() const override { return PLUGIN_TYPE_VIDEO_TOOL_BOX_PROXY; }
53 
54     explicit MediaH264DecoderVideoToolBoxProxy(uint64_t id,
55                                                H264PingInfoParser parser);
56     virtual ~MediaH264DecoderVideoToolBoxProxy();
57 
58 private:
59     using DecoderState = MediaH264DecoderVideoToolBox::DecoderState;
60 
61     uint64_t mId = 0;
62     H264PingInfoParser mParser;
63     unsigned int mWidth;
64     unsigned int mHeight;
65     unsigned int mOutputWidth;
66     unsigned int mOutputHeight;
67     PixelFormat  mOutputPixelFormat;
68 
69     std::vector<uint8_t> mSPS;
70     std::vector<uint8_t> mPPS;
71     bool mIsVideoToolBoxDecoderInGoodState = true;
72     MediaH264DecoderVideoToolBox mVideoToolBoxDecoder;
73     MediaH264DecoderFfmpeg mFfmpegDecoder;
74     MediaH264DecoderPlugin* mCurrentDecoder = nullptr;
75     std::vector<uint8_t> prefixNaluHeader(std::vector<uint8_t> data);
76 
77 }; // MediaH264DecoderVideoToolBoxProxy
78 
79 
80 }  // namespace emulation
81 }  // namespace android
82