*/
/**
- * @file libavformat/rdt.c
+ * @file
* @brief Realmedia RTSP protocol (RDT) support
* @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
*/
#include "libavutil/md5.h"
#include "rm.h"
#include "internal.h"
-#include "libavcodec/bitstream.h"
+#include "libavcodec/get_bits.h"
struct RDTDemuxContext {
AVFormatContext *ic; /**< the containing (RTSP) demux context */
s->prev_set_id = -1;
s->prev_stream_id = -1;
s->prev_timestamp = -1;
- s->parse_packet = handler->parse_packet;
+ s->parse_packet = handler ? handler->parse_packet : NULL;
s->dynamic_protocol_context = priv_data;
return s;
struct PayloadContext {
AVFormatContext *rmctx;
- RMStream *rmst[MAX_STREAMS];
+ int nb_rmst;
+ RMStream **rmst;
uint8_t *mlti_data;
unsigned int mlti_data_size;
char buffer[RTP_MAX_PACKET_LENGTH + FF_INPUT_BUFFER_PADDING_SIZE];
buf[8 + i] ^= xor_table[i];
av_md5_sum(zres, buf, 64);
- ff_data_to_hex(response, zres, 16);
- for (i=0;i<32;i++) response[i] = tolower(response[i]);
+ ff_data_to_hex(response, zres, 16, 1);
/* add tail */
strcpy (response + 32, "01d0a8e3");
/**
* Layout of the MLTI chunk:
- * 4:MLTI
- * 2:<number of streams>
+ * 4: MLTI
+ * 2: number of streams
* Then for each stream ([number_of_streams] times):
- * 2:<mdpr index>
- * 2:<number of mdpr chunks>
+ * 2: mdpr index
+ * 2: number of mdpr chunks
* Then for each mdpr chunk ([number_of_mdpr_chunks] times):
- * 4:<size>
- * [size]:<data>
+ * 4: size
+ * [size]: data
* we skip MDPR chunks until we reach the one of the stream
* we're interested in, and forward that ([size]+[data]) to
* the RM demuxer to parse the stream-specific header data.
init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
flags = (flags & RTP_FLAG_KEY) ? 2 : 0;
res = ff_rm_parse_packet (rdt->rmctx, &pb, st, rdt->rmst[st->index], len, pkt,
- &seq, &flags, timestamp);
+ &seq, flags, *timestamp);
pos = url_ftell(&pb);
if (res < 0)
return res;
- rdt->audio_pkt_cnt = res;
- if (rdt->audio_pkt_cnt > 0 &&
- st->codec->codec_id == CODEC_ID_AAC) {
- memcpy (rdt->buffer, buf + pos, len - pos);
- rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0,
- NULL, NULL, NULL, NULL);
+ if (res > 0) {
+ if (st->codec->codec_id == CODEC_ID_AAC) {
+ memcpy (rdt->buffer, buf + pos, len - pos);
+ rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0,
+ NULL, NULL, NULL, NULL);
+ }
+ goto get_cache;
}
} else {
+get_cache:
rdt->audio_pkt_cnt =
ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb,
st, rdt->rmst[st->index], pkt);
} else if (av_strstart(p, "StartTime:integer;", &p))
stream->first_dts = atoi(p);
else if (av_strstart(p, "ASMRuleBook:string;", &p)) {
- int n = st_index, first = -1;
+ int n, first = -1;
for (n = 0; n < s->nb_streams; n++)
if (s->streams[n]->priv_data == stream->priv_data) {
+ int count = s->streams[n]->index + 1;
if (first == -1) first = n;
+ if (rdt->nb_rmst < count) {
+ RMStream **rmst= av_realloc(rdt->rmst, count*sizeof(*rmst));
+ if (!rmst)
+ return AVERROR(ENOMEM);
+ memset(rmst + rdt->nb_rmst, 0,
+ (count - rdt->nb_rmst) * sizeof(*rmst));
+ rdt->rmst = rmst;
+ rdt->nb_rmst = count;
+ }
rdt->rmst[s->streams[n]->index] = ff_rm_alloc_rmstream();
rdt_load_mdpr(rdt, s->streams[n], (n - first) * 2);
const char *p)
{
const char *end;
- int n_rules, odd = 0;
+ int n_rules = 0, odd = 0;
AVStream *st;
/**
* for multi-bitrate streams.
*/
if (*p == '\"') p++;
- for (n_rules = 0; s->nb_streams < MAX_STREAMS;) {
+ while (1) {
if (!(end = strchr(p, ';')))
break;
if (!odd && end != p) {
st = add_dstream(s, orig_st);
else
st = orig_st;
+ if (!st)
+ break;
real_parse_asm_rule(st, p, end);
n_rules++;
}
}
static PayloadContext *
-rdt_new_extradata (void)
+rdt_new_context (void)
{
PayloadContext *rdt = av_mallocz(sizeof(PayloadContext));
}
static void
-rdt_free_extradata (PayloadContext *rdt)
+rdt_free_context (PayloadContext *rdt)
{
int i;
- for (i = 0; i < MAX_STREAMS; i++)
+ for (i = 0; i < rdt->nb_rmst; i++)
if (rdt->rmst[i]) {
ff_rm_free_rmstream(rdt->rmst[i]);
av_freep(&rdt->rmst[i]);
if (rdt->rmctx)
av_close_input_stream(rdt->rmctx);
av_freep(&rdt->mlti_data);
+ av_freep(&rdt->rmst);
av_free(rdt);
}
#define RDT_HANDLER(n, s, t) \
static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \
- s, \
- t, \
- CODEC_ID_NONE, \
- rdt_parse_sdp_line, \
- rdt_new_extradata, \
- rdt_free_extradata, \
- rdt_parse_packet \
+ .enc_name = s, \
+ .codec_type = t, \
+ .codec_id = CODEC_ID_NONE, \
+ .parse_sdp_a_line = rdt_parse_sdp_line, \
+ .open = rdt_new_context, \
+ .close = rdt_free_context, \
+ .parse_packet = rdt_parse_packet \
};
-RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", CODEC_TYPE_VIDEO);
-RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", CODEC_TYPE_AUDIO);
-RDT_HANDLER(video, "x-pn-realvideo", CODEC_TYPE_VIDEO);
-RDT_HANDLER(audio, "x-pn-realaudio", CODEC_TYPE_AUDIO);
+RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", AVMEDIA_TYPE_VIDEO);
+RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", AVMEDIA_TYPE_AUDIO);
+RDT_HANDLER(video, "x-pn-realvideo", AVMEDIA_TYPE_VIDEO);
+RDT_HANDLER(audio, "x-pn-realaudio", AVMEDIA_TYPE_AUDIO);
void av_register_rdt_dynamic_payload_handlers(void)
{