31 #include <boost/lexical_cast.hpp> 35 #include "libARSAL/ARSAL_Print.h" 47 throw std::runtime_error(message);
74 avcodec_register_all();
76 av_log_set_level(AV_LOG_QUIET);
78 codec_ptr_ = avcodec_find_decoder(AV_CODEC_ID_H264);
84 codec_ctx_ptr_->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
93 if (
codec_ptr_->capabilities & CODEC_CAP_TRUNCATED)
104 "Can not open the decoder!");
108 catch (
const std::runtime_error& e)
110 ARSAL_PRINT(ARSAL_PRINT_ERROR,
LOG_TAG,
"%s", e.what());
117 ARSAL_PRINT(ARSAL_PRINT_INFO,
LOG_TAG,
"H264 Codec is partially initialized!");
123 ARSAL_PRINT(ARSAL_PRINT_INFO,
LOG_TAG,
"Buffer reallocation request");
132 std::string(
"Invalid frame size:") +
141 frame_rgb_raw_ptr_ =
reinterpret_cast<uint8_t*
>(av_malloc(num_bytes *
sizeof(uint8_t)));
143 std::string(
"Can not allocate memory for the buffer: ") +
144 boost::lexical_cast<std::string>(num_bytes));
148 "Failed to initialize the picture data structure.");
152 SWS_FAST_BILINEAR, NULL, NULL, NULL);
154 catch (
const std::runtime_error& e)
156 ARSAL_PRINT(ARSAL_PRINT_ERROR,
LOG_TAG,
"%s", e.what());
181 ARSAL_PRINT(ARSAL_PRINT_INFO,
LOG_TAG,
"Buffer cleanup!");
200 ARSAL_PRINT(ARSAL_PRINT_INFO,
LOG_TAG,
"Reset!");
206 ARSAL_PRINT(ARSAL_PRINT_INFO,
LOG_TAG,
"Dstr!");
217 uint8_t *pps_buffer_ptr, uint32_t pps_buffer_size)
222 sps_buffer_size && pps_buffer_size &&
223 (pps_buffer_size < 32) && (sps_buffer_size < 32));
227 codec_data_.resize(sps_buffer_size + pps_buffer_size);
228 std::copy(sps_buffer_ptr, sps_buffer_ptr + sps_buffer_size,
codec_data_.begin());
229 std::copy(pps_buffer_ptr, pps_buffer_ptr + pps_buffer_size,
codec_data_.begin() + sps_buffer_size);
246 ARSAL_PRINT(ARSAL_PRINT_WARNING,
LOG_TAG,
"Codec initialization failed!");
263 ARSAL_PRINT(ARSAL_PRINT_INFO,
LOG_TAG,
"Updating H264 codec parameters (Buffer Size: %lu) ...",
codec_data_.size());
266 int32_t frame_finished = 0;
268 if (len >= 0 && len ==
packet_.size)
275 ARSAL_PRINT(ARSAL_PRINT_ERROR,
LOG_TAG,
"Unexpected error while updating H264 parameters.");
280 if (!bebop_frame_ptr_->data || !bebop_frame_ptr_->used)
282 ARSAL_PRINT(ARSAL_PRINT_ERROR,
LOG_TAG,
"Invalid frame data. Skipping.");
286 packet_.data = bebop_frame_ptr_->data;
287 packet_.size = bebop_frame_ptr_->used;
292 int32_t frame_finished = 0;
305 ARSAL_PRINT(ARSAL_PRINT_ERROR,
LOG_TAG,
"Buffer reallocation failed!");
bool update_codec_params_
uint32_t GetFrameHeight() const
uint8_t * frame_rgb_raw_ptr_
AVInputFormat * input_format_ptr_
bool Decode(const ARCONTROLLER_Frame_t *bebop_frame_ptr_)
bool SetH264Params(uint8_t *sps_buffer_ptr, uint32_t sps_buffer_size, uint8_t *pps_buffer_ptr, uint32_t pps_buffer_size)
std::vector< uint8_t > codec_data_
SwsContext * img_convert_ctx_ptr_
AVCodecContext * codec_ctx_ptr_
static const char * LOG_TAG
uint32_t GetFrameWidth() const
static void ThrowOnCondition(const bool cond, const std::string &message)
AVFormatContext * format_ctx_ptr_