mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
rtpdec: factorize identical code used in several handlers
This commit is contained in:
parent
f70381ab9d
commit
179a5c37e0
@ -803,3 +803,14 @@ int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
|
|||||||
av_free(value);
|
av_free(value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx)
|
||||||
|
{
|
||||||
|
av_init_packet(pkt);
|
||||||
|
|
||||||
|
pkt->size = avio_close_dyn_buf(*dyn_buf, &pkt->data);
|
||||||
|
pkt->stream_index = stream_idx;
|
||||||
|
pkt->destruct = av_destruct_packet;
|
||||||
|
*dyn_buf = NULL;
|
||||||
|
return pkt->size;
|
||||||
|
}
|
||||||
|
@ -202,4 +202,9 @@ int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p,
|
|||||||
|
|
||||||
void av_register_rtp_dynamic_payload_handlers(void);
|
void av_register_rtp_dynamic_payload_handlers(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the dynamic buffer and make a packet from it.
|
||||||
|
*/
|
||||||
|
int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx);
|
||||||
|
|
||||||
#endif /* AVFORMAT_RTPDEC_H */
|
#endif /* AVFORMAT_RTPDEC_H */
|
||||||
|
@ -61,7 +61,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
|||||||
{
|
{
|
||||||
/* Corresponding to header fields in the RFC */
|
/* Corresponding to header fields in the RFC */
|
||||||
int f, p, i, sbit, ebit, src, r;
|
int f, p, i, sbit, ebit, src, r;
|
||||||
int header_size;
|
int header_size, ret;
|
||||||
|
|
||||||
if (data->newformat)
|
if (data->newformat)
|
||||||
return ff_h263_handle_packet(ctx, data, st, pkt, timestamp, buf, len,
|
return ff_h263_handle_packet(ctx, data, st, pkt, timestamp, buf, len,
|
||||||
@ -133,7 +133,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
|||||||
/* Check the picture start code, only start buffering a new frame
|
/* Check the picture start code, only start buffering a new frame
|
||||||
* if this is correct */
|
* if this is correct */
|
||||||
if (len > 4 && AV_RB32(buf) >> 10 == 0x20) {
|
if (len > 4 && AV_RB32(buf) >> 10 == 0x20) {
|
||||||
int ret = avio_open_dyn_buf(&data->buf);
|
ret = avio_open_dyn_buf(&data->buf);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
data->timestamp = *timestamp;
|
data->timestamp = *timestamp;
|
||||||
@ -185,13 +185,11 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
|
|||||||
avio_w8(data->buf, data->endbyte);
|
avio_w8(data->buf, data->endbyte);
|
||||||
data->endbyte_bits = 0;
|
data->endbyte_bits = 0;
|
||||||
|
|
||||||
av_init_packet(pkt);
|
ret = ff_rtp_finalize_packet(pkt, &data->buf, st->index);
|
||||||
pkt->size = avio_close_dyn_buf(data->buf, &pkt->data);
|
if (ret < 0)
|
||||||
pkt->destruct = av_destruct_packet;
|
return ret;
|
||||||
pkt->stream_index = st->index;
|
|
||||||
if (!i)
|
if (!i)
|
||||||
pkt->flags |= AV_PKT_FLAG_KEY;
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
||||||
data->buf = NULL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "avformat.h"
|
#include "avformat.h"
|
||||||
|
#include "rtpdec.h"
|
||||||
#include "rtpdec_formats.h"
|
#include "rtpdec_formats.h"
|
||||||
#include "libavutil/intreadwrite.h"
|
#include "libavutil/intreadwrite.h"
|
||||||
#include "libavcodec/mjpeg.h"
|
#include "libavcodec/mjpeg.h"
|
||||||
@ -367,19 +368,11 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
|
|||||||
avio_write(jpeg->frame, buf, sizeof(buf));
|
avio_write(jpeg->frame, buf, sizeof(buf));
|
||||||
|
|
||||||
/* Prepare the JPEG packet. */
|
/* Prepare the JPEG packet. */
|
||||||
av_init_packet(pkt);
|
if ((ret = ff_rtp_finalize_packet(pkt, &jpeg->frame, st->index)) < 0) {
|
||||||
pkt->size = avio_close_dyn_buf(jpeg->frame, &pkt->data);
|
|
||||||
if (pkt->size < 0) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
"Error occured when getting frame buffer.\n");
|
"Error occured when getting frame buffer.\n");
|
||||||
jpeg->frame = NULL;
|
return ret;
|
||||||
return pkt->size;
|
|
||||||
}
|
}
|
||||||
pkt->stream_index = st->index;
|
|
||||||
pkt->destruct = av_destruct_packet;
|
|
||||||
|
|
||||||
/* Re-init the frame buffer. */
|
|
||||||
jpeg->frame = NULL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -97,12 +97,11 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
|
|||||||
avio_write(sv->pktbuf, buf, len);
|
avio_write(sv->pktbuf, buf, len);
|
||||||
|
|
||||||
if (end_packet) {
|
if (end_packet) {
|
||||||
av_init_packet(pkt);
|
int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
|
||||||
pkt->stream_index = st->index;
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
*timestamp = sv->timestamp;
|
*timestamp = sv->timestamp;
|
||||||
pkt->size = avio_close_dyn_buf(sv->pktbuf, &pkt->data);
|
|
||||||
pkt->destruct = av_destruct_packet;
|
|
||||||
sv->pktbuf = NULL;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,15 +36,6 @@ struct PayloadContext {
|
|||||||
uint32_t timestamp;
|
uint32_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void prepare_packet(AVPacket *pkt, PayloadContext *vp8, int stream)
|
|
||||||
{
|
|
||||||
av_init_packet(pkt);
|
|
||||||
pkt->stream_index = stream;
|
|
||||||
pkt->size = avio_close_dyn_buf(vp8->data, &pkt->data);
|
|
||||||
pkt->destruct = av_destruct_packet;
|
|
||||||
vp8->data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int vp8_handle_packet(AVFormatContext *ctx,
|
static int vp8_handle_packet(AVFormatContext *ctx,
|
||||||
PayloadContext *vp8,
|
PayloadContext *vp8,
|
||||||
AVStream *st,
|
AVStream *st,
|
||||||
@ -133,7 +124,9 @@ static int vp8_handle_packet(AVFormatContext *ctx,
|
|||||||
avio_write(vp8->data, buf, len);
|
avio_write(vp8->data, buf, len);
|
||||||
|
|
||||||
if (end_packet) {
|
if (end_packet) {
|
||||||
prepare_packet(pkt, vp8, st->index);
|
int ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,20 +202,13 @@ static int xiph_handle_packet(AVFormatContext * ctx,
|
|||||||
|
|
||||||
if (fragmented == 3) {
|
if (fragmented == 3) {
|
||||||
// end of xiph data packet
|
// end of xiph data packet
|
||||||
av_init_packet(pkt);
|
int ret = ff_rtp_finalize_packet(pkt, &data->fragment, st->index);
|
||||||
pkt->size = avio_close_dyn_buf(data->fragment, &pkt->data);
|
if (ret < 0) {
|
||||||
|
|
||||||
if (pkt->size < 0) {
|
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
av_log(ctx, AV_LOG_ERROR,
|
||||||
"Error occurred when getting fragment buffer.");
|
"Error occurred when getting fragment buffer.");
|
||||||
return pkt->size;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt->stream_index = st->index;
|
|
||||||
pkt->destruct = av_destruct_packet;
|
|
||||||
|
|
||||||
data->fragment = NULL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user