OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 * | 9 * |
10 */ | 10 */ |
11 | 11 |
12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ | 12 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ |
13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ | 13 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ |
14 | 14 |
15 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | 15 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
| 16 #include "webrtc/modules/video_coding/codecs/vp9/screenshare_layers.h" |
16 #include "webrtc/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h" | 17 #include "webrtc/modules/video_coding/codecs/vp9/vp9_frame_buffer_pool.h" |
17 | 18 |
18 #include "vpx/svc_context.h" | 19 #include "vpx/svc_context.h" |
19 #include "vpx/vpx_decoder.h" | 20 #include "vpx/vpx_decoder.h" |
20 #include "vpx/vpx_encoder.h" | 21 #include "vpx/vpx_encoder.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
24 class VP9EncoderImpl : public VP9Encoder { | 25 class VP9EncoderImpl : public VP9Encoder { |
25 public: | 26 public: |
(...skipping 25 matching lines...) Expand all Loading... |
51 | 52 |
52 // Call encoder initialize function and set control settings. | 53 // Call encoder initialize function and set control settings. |
53 int InitAndSetControlSettings(const VideoCodec* inst); | 54 int InitAndSetControlSettings(const VideoCodec* inst); |
54 | 55 |
55 void PopulateCodecSpecific(CodecSpecificInfo* codec_specific, | 56 void PopulateCodecSpecific(CodecSpecificInfo* codec_specific, |
56 const vpx_codec_cx_pkt& pkt, | 57 const vpx_codec_cx_pkt& pkt, |
57 uint32_t timestamp); | 58 uint32_t timestamp); |
58 | 59 |
59 bool SetSvcRates(); | 60 bool SetSvcRates(); |
60 | 61 |
| 62 /* |
| 63 * Generate the flags used when calling vpx_encoder_encode and also |
| 64 * saves information used to reference this frame to earlier frames. |
| 65 * Used in flexible mode and has to be called for every frame (even |
| 66 * keyframes) in order to update its state. The information used |
| 67 * for references is saved in p_diff_ and num_ref_pics_. |
| 68 * |
| 69 * upd_buffer - which buffer to update: |
| 70 * -2: this is a keyframe, always stored in buffer |
| 71 * 0 and all other params are ignored |
| 72 * -1: don't update any buffers |
| 73 * 0..2: update buffer 0..2 |
| 74 * |
| 75 * ref_buf1, ref_buf2, ref_buf3 - which buffers to reference back to: |
| 76 * -1: don't reference any buffer |
| 77 * 0..2: reference buffer 0..2 |
| 78 * |
| 79 */ |
| 80 vpx_enc_frame_flags_t GenerateRefsAndFlags(int8_t upd_buffer = -2, |
| 81 int8_t ref_buf1 = -1, |
| 82 int8_t ref_buf2 = -1, |
| 83 int8_t ref_buf3 = -1); |
| 84 vpx_enc_frame_flags_t GenerateRefsAndFlags(std::array<int8_t, 4> args); |
| 85 |
61 virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt); | 86 virtual int GetEncodedLayerFrame(const vpx_codec_cx_pkt* pkt); |
62 | 87 |
63 // Callback function for outputting packets per spatial layer. | 88 // Callback function for outputting packets per spatial layer. |
64 static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt, | 89 static void EncoderOutputCodedPacketCallback(vpx_codec_cx_pkt* pkt, |
65 void* user_data); | 90 void* user_data); |
66 | 91 |
67 // Determine maximum target for Intra frames | 92 // Determine maximum target for Intra frames |
68 // | 93 // |
69 // Input: | 94 // Input: |
70 // - optimal_buffer_size : Optimal buffer size | 95 // - optimal_buffer_size : Optimal buffer size |
(...skipping 10 matching lines...) Expand all Loading... |
81 int cpu_speed_; | 106 int cpu_speed_; |
82 uint32_t rc_max_intra_target_; | 107 uint32_t rc_max_intra_target_; |
83 vpx_codec_ctx_t* encoder_; | 108 vpx_codec_ctx_t* encoder_; |
84 vpx_codec_enc_cfg_t* config_; | 109 vpx_codec_enc_cfg_t* config_; |
85 vpx_image_t* raw_; | 110 vpx_image_t* raw_; |
86 SvcInternal_t svc_internal_; | 111 SvcInternal_t svc_internal_; |
87 const VideoFrame* input_image_; | 112 const VideoFrame* input_image_; |
88 GofInfoVP9 gof_; // Contains each frame's temporal information for | 113 GofInfoVP9 gof_; // Contains each frame's temporal information for |
89 // non-flexible mode. | 114 // non-flexible mode. |
90 uint8_t tl0_pic_idx_; // Only used in non-flexible mode. | 115 uint8_t tl0_pic_idx_; // Only used in non-flexible mode. |
91 size_t gof_idx_; // Only used in non-flexible mode. | 116 size_t frames_since_kf_; |
92 uint8_t num_temporal_layers_; | 117 uint8_t num_temporal_layers_; |
93 uint8_t num_spatial_layers_; | 118 uint8_t num_spatial_layers_; |
| 119 |
| 120 // Used for flexible mode |
| 121 bool is_flexible_mode_; |
| 122 int64_t buf_upd_at_frame_[8]; |
| 123 int64_t frames_encoded_; |
| 124 uint8_t num_refs_pics_; |
| 125 uint8_t p_diff_[kMaxVp9RefPics]; |
| 126 ScreenshareLayersVP9 temporal_layer_; |
94 }; | 127 }; |
95 | 128 |
96 | 129 |
97 class VP9DecoderImpl : public VP9Decoder { | 130 class VP9DecoderImpl : public VP9Decoder { |
98 public: | 131 public: |
99 VP9DecoderImpl(); | 132 VP9DecoderImpl(); |
100 | 133 |
101 virtual ~VP9DecoderImpl(); | 134 virtual ~VP9DecoderImpl(); |
102 | 135 |
103 int InitDecode(const VideoCodec* inst, int number_of_cores) override; | 136 int InitDecode(const VideoCodec* inst, int number_of_cores) override; |
(...skipping 17 matching lines...) Expand all Loading... |
121 Vp9FrameBufferPool frame_buffer_pool_; | 154 Vp9FrameBufferPool frame_buffer_pool_; |
122 DecodedImageCallback* decode_complete_callback_; | 155 DecodedImageCallback* decode_complete_callback_; |
123 bool inited_; | 156 bool inited_; |
124 vpx_codec_ctx_t* decoder_; | 157 vpx_codec_ctx_t* decoder_; |
125 VideoCodec codec_; | 158 VideoCodec codec_; |
126 bool key_frame_required_; | 159 bool key_frame_required_; |
127 }; | 160 }; |
128 } // namespace webrtc | 161 } // namespace webrtc |
129 | 162 |
130 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ | 163 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP9_IMPL_H_ |
OLD | NEW |