hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2019 Fuzhou Rockchip Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
#ifndef EASYMEDIA_MPP_ENCODER_H
#define EASYMEDIA_MPP_ENCODER_H
 
#include "encoder.h"
#include "mpp_inc.h"
#include "mpp_rc_api.h"
#include "rk_venc_cfg.h"
 
namespace easymedia
{
 
    // A encoder which call the mpp interface directly.
    // Mpp is always video process module.
    class MPPEncoder : public VideoEncoder
    {
      public:
        MPPEncoder();
        virtual ~MPPEncoder();
 
        virtual bool Init() override;
 
        // sync encode the raw input buffer to output buffer
        virtual int Process(const std::shared_ptr<MediaBuffer>& input, std::shared_ptr<MediaBuffer>& output,
                            std::shared_ptr<MediaBuffer> extra_output) override;
 
        virtual int SendInput(const std::shared_ptr<MediaBuffer>&) override;
        virtual std::shared_ptr<MediaBuffer> FetchOutput() override;
 
        // Encoder statistics enable switch. After enabling, calculate the
        // actual bps and actual fps every theoretical fps period.
        // Input parameters:
        //   value = true, enable encoder statistics.
        //   value = false, disable encoding statistics.
        void set_statistics_switch(bool value);
        int get_statistics_bps();
        int get_statistics_fps();
 
#ifdef MPP_SUPPORT_HW_OSD
        int OsdPaletteSet(uint32_t* ptl_data);
        int OsdRegionSet(OsdRegionData* region_data);
        int OsdRegionGet(OsdRegionData* region_data);
#endif
 
        // Set sei info by userdata.
        int SetUserData(const char* data, uint16_t len);
        void ClearUserData();
        void RestartUserData();
        void EnableUserDataAllFrame(bool value);
 
        // for updating roi regions config.
        int RoiUpdateRegions(EncROIRegion* regions, int region_cnt);
 
        virtual void QueryChange(uint32_t change, void* value, int32_t size);
 
      protected:
        MppCodingType coding_type;
        uint32_t output_mb_flags;
        std::string rc_api_brief_name;
        // call before Init()
        void SetMppCodeingType(MppCodingType type);
        virtual bool CheckConfigChange(std::pair<uint32_t, std::shared_ptr<ParameterBuffer>>)
        {
            return true;
        }
        // Control before encoding.
        int EncodeControl(int cmd, void* param);
 
        virtual int PrepareMppFrame(const std::shared_ptr<MediaBuffer>& input, std::shared_ptr<MediaBuffer>& mdinfo,
                                    MppFrame& frame);
        virtual int PrepareMppPacket(std::shared_ptr<MediaBuffer>& output, MppPacket& packet);
        virtual int PrepareMppExtraBuffer(std::shared_ptr<MediaBuffer> extra_output, MppBuffer& buffer);
        int Process(MppFrame frame, MppPacket& packet, MppBuffer& mv_buf);
 
      private:
        std::shared_ptr<MPPContext> mpp_ctx;
 
        // Statistics switch
        bool encoder_sta_en;
        // Statistics variable
        uint32_t encoded_bps;
        float encoded_fps;
 
        size_t stream_size_1s;
        size_t frame_cnt_1s;
        int64_t last_ts;
        int64_t cur_ts;
 
#ifdef MPP_SUPPORT_HW_OSD
        MppEncOSDData osd_data;
#endif // MPP_SUPPORT_HW_OSD
 
        // for roi regions config.
        MppEncROICfg roi_cfg;
 
#define MPP_ENCODER_USERDATA_MAX_SIZE 1024
        char userdata[MPP_ENCODER_USERDATA_MAX_SIZE];
        uint16_t userdata_len;
        uint16_t userdata_frame_id;
        uint8_t userdata_all_frame_en;
        MppEncUserData mpp_ud;
 
        friend class MPPMJPEGConfig;
        friend class MPPCommonConfig;
    };
 
} // namespace easymedia
 
#endif // EASYMEDIA_MPP_ENCODER_H