aboutsummaryrefslogtreecommitdiff
path: root/system/codecs/omx/avcdec/include/MediaH264Decoder.h
blob: a75758faabedb621dcb7f1ef7fad5eaae0718c06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GOLDFISH_MEDIA_H264_DEC_H_
#define GOLDFISH_MEDIA_H264_DEC_H_

struct h264_init_result_t {
    uint64_t host_handle;
    int ret;
};

struct h264_result_t {
    int ret;
    uint64_t bytesProcessed;
};

struct h264_image_t {
    const uint8_t* data;
    uint32_t width;
    uint32_t height;
    uint64_t pts; // presentation time stamp
    uint64_t color_primaries;
    uint64_t color_range;
    uint64_t color_trc;
    uint64_t colorspace;
    // on success, |ret| will indicate the size of |data|.
    // If failed, |ret| will contain some negative error code.
    int ret;
};

enum class RenderMode {
  RENDER_BY_HOST_GPU = 1,
  RENDER_BY_GUEST_CPU = 2,
};

class MediaH264Decoder {
    uint64_t mHostHandle = 0;
    uint32_t mVersion = 100;
    RenderMode  mRenderMode = RenderMode::RENDER_BY_GUEST_CPU;

    bool mHasAddressSpaceMemory = false;
    uint64_t mAddressOffSet = 0;
    int mSlot = -1;

public:
    MediaH264Decoder(RenderMode renderMode);
    virtual ~MediaH264Decoder() = default;

    enum class PixelFormat : uint8_t {
        YUV420P = 0,
        UYVY422 = 1,
        BGRA8888 = 2,
    };

    enum class Err : int {
        NoErr = 0,
        NoDecodedFrame = -1,
        InitContextFailed = -2,
        DecoderRestarted = -3,
        NALUIgnored = -4,
    };

    bool getAddressSpaceMemory();
    void initH264Context(unsigned int width,
                         unsigned int height,
                         unsigned int outWidth,
                         unsigned int outHeight,
                         PixelFormat pixFmt);
    void resetH264Context(unsigned int width,
                         unsigned int height,
                         unsigned int outWidth,
                         unsigned int outHeight,
                         PixelFormat pixFmt);
    void destroyH264Context();
    h264_result_t decodeFrame(uint8_t* img, size_t szBytes, uint64_t pts);
    void flush();
    // ask host to copy image data back to guest, with image metadata
    // to guest as well
    h264_image_t getImage();
    // ask host to render to hostColorBufferId, return only image metadata back to
    // guest
    h264_image_t renderOnHostAndReturnImageMetadata(int hostColorBufferId);
};
#endif