fix: display channel info

This commit is contained in:
2024-11-05 13:57:13 +00:00
parent bc39a2ad99
commit ba53d2eeb9
4 changed files with 87 additions and 38 deletions

View File

@ -7,14 +7,13 @@ use std::ptr;
use anyhow::Error;
use ffmpeg_sys_the_third::AVPictureType::AV_PICTURE_TYPE_NONE;
use ffmpeg_sys_the_third::{
av_buffer_alloc, av_buffer_ref, av_frame_alloc, av_frame_copy_props, av_frame_free,
av_hwdevice_ctx_create, av_hwdevice_get_type_name, av_hwframe_transfer_data,
avcodec_alloc_context3, avcodec_find_decoder, avcodec_free_context, avcodec_get_hw_config,
avcodec_get_name, avcodec_open2, avcodec_parameters_to_context, avcodec_receive_frame,
avcodec_send_packet, AVCodec, AVCodecContext, AVCodecHWConfig, AVFrame, AVHWDeviceType,
AVMediaType, AVPacket, AVStream, AVERROR, AVERROR_EOF, AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
av_buffer_ref, av_frame_alloc, av_frame_copy_props, av_frame_free, av_hwdevice_ctx_create,
av_hwdevice_get_type_name, av_hwframe_transfer_data, avcodec_alloc_context3,
avcodec_find_decoder, avcodec_free_context, avcodec_get_hw_config, avcodec_get_name,
avcodec_open2, avcodec_parameters_to_context, avcodec_receive_frame, avcodec_send_packet,
AVCodec, AVCodecContext, AVCodecHWConfig, AVFrame, AVHWDeviceType, AVPacket, AVStream, AVERROR,
AVERROR_EOF, AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX,
};
use libc::memcpy;
pub struct DecoderCodecContext {
pub context: *mut AVCodecContext,
@ -204,23 +203,6 @@ impl Decoder {
);
if let Some(ctx) = self.codecs.get_mut(&stream_index) {
// subtitles don't need decoding, create a frame from the pkt data
if (*ctx.codec).type_ == AVMediaType::AVMEDIA_TYPE_SUBTITLE {
let frame = av_frame_alloc();
(*frame).pts = (*pkt).pts;
(*frame).pkt_dts = (*pkt).dts;
(*frame).duration = (*pkt).duration;
(*frame).buf[0] = av_buffer_alloc((*pkt).size as usize);
(*frame).data[0] = (*(*frame).buf[0]).data;
(*frame).linesize[0] = (*pkt).size;
memcpy(
(*frame).data[0] as *mut libc::c_void,
(*pkt).data as *const libc::c_void,
(*pkt).size as usize,
);
return Ok(vec![(frame, stream)]);
}
let mut ret = avcodec_send_packet(ctx.context, pkt);
if ret < 0 {
return Err(Error::msg(format!("Failed to decode packet {}", ret)));