remove all usages of av_packet_from_data

This commit is contained in:
MattKC 2024-11-16 00:25:22 -08:00
parent 7788aebd8b
commit 1ed2d7caf1
2 changed files with 13 additions and 38 deletions

View file

@ -68,17 +68,8 @@ void VideoDecoder::sendPacket(const QByteArray &data)
{ {
int ret; int ret;
// Copy data into buffer that FFmpeg will take ownership of m_packet->data = (uint8_t *) data.constData();
uint8_t *buffer = (uint8_t *) av_malloc(data.size()); m_packet->size = data.size();
memcpy(buffer, data.data(), data.size());
// Create AVPacket from this data
ret = av_packet_from_data(m_packet, buffer, data.size());
if (ret < 0) {
fprintf(stderr, "Failed to initialize packet from data: %i\n", ret);
av_free(buffer);
return;
}
// If recording, send packet to file // If recording, send packet to file
if (m_recordingCtx) { if (m_recordingCtx) {
@ -96,7 +87,6 @@ void VideoDecoder::sendPacket(const QByteArray &data)
// Send packet to decoder // Send packet to decoder
ret = avcodec_send_packet(m_codecCtx, m_packet); ret = avcodec_send_packet(m_codecCtx, m_packet);
av_packet_unref(m_packet);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Failed to send packet to decoder: %i\n", ret); fprintf(stderr, "Failed to send packet to decoder: %i\n", ret);
return; return;
@ -134,30 +124,20 @@ void VideoDecoder::sendAudio(const QByteArray &data)
if (m_recordingCtx) { if (m_recordingCtx) {
int ret; int ret;
// Copy data into buffer that FFmpeg will take ownership of
uint8_t *buffer = (uint8_t *) av_malloc(data.size());
memcpy(buffer, data.data(), data.size());
// Create AVPacket from this data // Create AVPacket from this data
AVPacket *audPkt = av_packet_alloc(); AVPacket audPkt = {0};
int64_t ts; av_packet_unref(&audPkt);
ret = av_packet_from_data(audPkt, buffer, data.size());
if (ret < 0) {
fprintf(stderr, "Failed to initialize packet from data: %i\n", ret);
av_free(buffer);
goto free;
}
ts = getCurrentTimestamp(m_audioStream->time_base); audPkt.data = (uint8_t *) data.constData();
audPkt.size = data.size();
audPkt->stream_index = AUDIO_STREAM_INDEX; int64_t ts = getCurrentTimestamp(m_audioStream->time_base);
audPkt->dts = ts;
audPkt->pts = ts;
av_interleaved_write_frame(m_recordingCtx, audPkt); audPkt.stream_index = AUDIO_STREAM_INDEX;
audPkt.dts = ts;
audPkt.pts = ts;
free: av_interleaved_write_frame(m_recordingCtx, &audPkt);
av_packet_free(&audPkt);
} }
} }

View file

@ -53,16 +53,11 @@ int decode(void *data, size_t size)
int err; int err;
// Parse this data for packets // Parse this data for packets
err = av_packet_from_data(video_packet, (uint8_t *) data, size); video_packet->data = data;
if (err < 0) { video_packet->size = size;
fprintf(stderr, "Failed to initialize AVPacket from data: %s (%i)\n", av_err2str(err), err);
av_free(data);
return 0;
}
// Send packet to decoder // Send packet to decoder
err = avcodec_send_packet(video_codec_ctx, video_packet); err = avcodec_send_packet(video_codec_ctx, video_packet);
av_packet_unref(video_packet);
if (err < 0) { if (err < 0) {
fprintf(stderr, "Failed to send packet to decoder: %s (%i)\n", av_err2str(err), err); fprintf(stderr, "Failed to send packet to decoder: %s (%i)\n", av_err2str(err), err);
return 0; return 0;