rtpdec: Split mpegts parsing to a normal depacketizer
This gets rid of a number of special cases from the common rtpdec code. Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
d5bb8cc2dd
commit
2326558d52
6 changed files with 131 additions and 55 deletions
|
@ -24,7 +24,6 @@
|
|||
#include "libavutil/time.h"
|
||||
#include "libavcodec/get_bits.h"
|
||||
#include "avformat.h"
|
||||
#include "mpegts.h"
|
||||
#include "network.h"
|
||||
#include "srtp.h"
|
||||
#include "url.h"
|
||||
|
@ -76,6 +75,7 @@ void av_register_rtp_dynamic_payload_handlers(void)
|
|||
ff_register_dynamic_payload_handler(&ff_mp4a_latm_dynamic_handler);
|
||||
ff_register_dynamic_payload_handler(&ff_mp4v_es_dynamic_handler);
|
||||
ff_register_dynamic_payload_handler(&ff_mpeg4_generic_dynamic_handler);
|
||||
ff_register_dynamic_payload_handler(&ff_mpegts_dynamic_handler);
|
||||
ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfv_handler);
|
||||
ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfa_handler);
|
||||
ff_register_dynamic_payload_handler(&ff_qcelp_dynamic_handler);
|
||||
|
@ -481,8 +481,7 @@ int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd,
|
|||
|
||||
/**
|
||||
* open a new RTP parse context for stream 'st'. 'st' can be NULL for
|
||||
* MPEG2-TS streams to indicate that they should be demuxed inside the
|
||||
* rtp demux (otherwise AV_CODEC_ID_MPEG2TS packets are returned)
|
||||
* MPEG2-TS streams.
|
||||
*/
|
||||
RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st,
|
||||
int payload_type, int queue_size)
|
||||
|
@ -499,13 +498,7 @@ RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st,
|
|||
s->st = st;
|
||||
s->queue_size = queue_size;
|
||||
rtp_init_statistics(&s->statistics, 0);
|
||||
if (!strcmp(ff_rtp_enc_name(payload_type), "MP2T")) {
|
||||
s->ts = ff_mpegts_parse_open(s->ic);
|
||||
if (s->ts == NULL) {
|
||||
av_free(s);
|
||||
return NULL;
|
||||
}
|
||||
} else if (st) {
|
||||
if (st) {
|
||||
switch (st->codec->codec_id) {
|
||||
case AV_CODEC_ID_MPEG1VIDEO:
|
||||
case AV_CODEC_ID_MPEG2VIDEO:
|
||||
|
@ -591,7 +584,7 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
|
|||
const uint8_t *buf, int len)
|
||||
{
|
||||
unsigned int ssrc, h;
|
||||
int payload_type, seq, ret, flags = 0;
|
||||
int payload_type, seq, flags = 0;
|
||||
int ext;
|
||||
AVStream *st;
|
||||
uint32_t timestamp;
|
||||
|
@ -645,26 +638,11 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
|
|||
buf += ext;
|
||||
}
|
||||
|
||||
if (!st) {
|
||||
/* specific MPEG2-TS demux support */
|
||||
ret = ff_mpegts_parse_packet(s->ts, pkt, buf, len);
|
||||
/* The only error that can be returned from ff_mpegts_parse_packet
|
||||
* is "no more data to return from the provided buffer", so return
|
||||
* AVERROR(EAGAIN) for all errors */
|
||||
if (ret < 0)
|
||||
return AVERROR(EAGAIN);
|
||||
if (ret < len) {
|
||||
s->read_buf_size = FFMIN(len - ret, sizeof(s->buf));
|
||||
memcpy(s->buf, buf + ret, s->read_buf_size);
|
||||
s->read_buf_index = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else if (s->handler && s->handler->parse_packet) {
|
||||
if (s->handler && s->handler->parse_packet) {
|
||||
rv = s->handler->parse_packet(s->ic, s->dynamic_protocol_context,
|
||||
s->st, pkt, ×tamp, buf, len, seq,
|
||||
flags);
|
||||
} else {
|
||||
} else if (st) {
|
||||
/* At this point, the RTP header has been stripped;
|
||||
* This is ASSUMING that there is only 1 CSRC, which isn't wise. */
|
||||
switch (st->codec->codec_id) {
|
||||
|
@ -704,6 +682,8 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
|
|||
}
|
||||
|
||||
pkt->stream_index = st->index;
|
||||
} else {
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
// now perform timestamp things....
|
||||
|
@ -786,7 +766,7 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
|
|||
uint8_t **bufptr, int len)
|
||||
{
|
||||
uint8_t *buf = bufptr ? *bufptr : NULL;
|
||||
int ret, flags = 0;
|
||||
int flags = 0;
|
||||
uint32_t timestamp;
|
||||
int rv = 0;
|
||||
|
||||
|
@ -797,7 +777,7 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
|
|||
if (s->prev_ret <= 0)
|
||||
return rtp_parse_queued_packet(s, pkt);
|
||||
/* return the next packets, if any */
|
||||
if (s->st && s->handler && s->handler->parse_packet) {
|
||||
if (s->handler && s->handler->parse_packet) {
|
||||
/* timestamp should be overwritten by parse_packet, if not,
|
||||
* the packet is left with pts == AV_NOPTS_VALUE */
|
||||
timestamp = RTP_NOTS_VALUE;
|
||||
|
@ -806,19 +786,6 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
|
|||
flags);
|
||||
finalize_packet(s, pkt, timestamp);
|
||||
return rv;
|
||||
} else {
|
||||
// TODO: Move to a dynamic packet handler (like above)
|
||||
if (s->read_buf_index >= s->read_buf_size)
|
||||
return AVERROR(EAGAIN);
|
||||
ret = ff_mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index,
|
||||
s->read_buf_size - s->read_buf_index);
|
||||
if (ret < 0)
|
||||
return AVERROR(EAGAIN);
|
||||
s->read_buf_index += ret;
|
||||
if (s->read_buf_index < s->read_buf_size)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -894,9 +861,6 @@ int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
|
|||
void ff_rtp_parse_close(RTPDemuxContext *s)
|
||||
{
|
||||
ff_rtp_reset_packet_queue(s);
|
||||
if (!strcmp(ff_rtp_enc_name(s->payload_type), "MP2T")) {
|
||||
ff_mpegts_parse_close(s->ts);
|
||||
}
|
||||
ff_srtp_free(&s->srtp);
|
||||
av_free(s);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue