diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-09-19 13:01:26 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-09-19 13:01:26 +0400 |
commit | 20dfab33f5ab61fc51de65192ed239f8b62782a2 (patch) | |
tree | f5164b3f79ab48e4dd4c027bef968666f7748716 /libavformat/rtmpproto.c | |
parent | f54d751f33375054d4ecf30301ef008c8e781f99 (diff) | |
parent | 5626f994f273af80fb100d4743b963304de9e05c (diff) |
Merge commit '5626f994f273af80fb100d4743b963304de9e05c'
* commit '5626f994f273af80fb100d4743b963304de9e05c':
avformat: Use av_reallocp() where suitable
Conflicts:
libavformat/avidec.c
libavformat/avienc.c
libavformat/aviobuf.c
libavformat/oggparsevorbis.c
libavformat/utils.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/rtmpproto.c')
-rw-r--r-- | libavformat/rtmpproto.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index e8aecfef67..8be5cb47ed 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -150,15 +150,13 @@ static const uint8_t rtmp_server_key[] = { static int add_tracked_method(RTMPContext *rt, const char *name, int id) { - void *ptr; + int err; if (rt->nb_tracked_methods + 1 > rt->tracked_methods_size) { rt->tracked_methods_size = (rt->nb_tracked_methods + 1) * 2; - ptr = av_realloc(rt->tracked_methods, - rt->tracked_methods_size * sizeof(*rt->tracked_methods)); - if (!ptr) - return AVERROR(ENOMEM); - rt->tracked_methods = ptr; + if ((err = av_reallocp(&rt->tracked_methods, rt->tracked_methods_size * + sizeof(*rt->tracked_methods))) < 0) + return err; } rt->tracked_methods[rt->nb_tracked_methods].name = av_strdup(name); @@ -2063,7 +2061,6 @@ static int handle_invoke(URLContext *s, RTMPPacket *pkt) static int handle_notify(URLContext *s, RTMPPacket *pkt) { RTMPContext *rt = s->priv_data; const uint8_t *p = NULL; - uint8_t *cp = NULL; uint8_t commandbuffer[64]; char statusmsg[128]; int stringlen; @@ -2098,25 +2095,22 @@ static int handle_notify(URLContext *s, RTMPPacket *pkt) { old_flv_size = rt->flv_size; rt->flv_size += datatowritelength + 15; } else { + int err; old_flv_size = 0; rt->flv_size = datatowritelength + 15; rt->flv_off = 0; + if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0) + return err; + bytestream2_init_writer(&pbc, rt->flv_data, rt->flv_size); + bytestream2_skip_p(&pbc, old_flv_size); + bytestream2_put_byte(&pbc, pkt->type); + bytestream2_put_be24(&pbc, datatowritelength); + bytestream2_put_be24(&pbc, ts); + bytestream2_put_byte(&pbc, ts >> 24); + bytestream2_put_be24(&pbc, 0); + bytestream2_put_buffer(&pbc, datatowrite, datatowritelength); + bytestream2_put_be32(&pbc, 0); } - - cp = av_realloc(rt->flv_data, rt->flv_size); - if (!cp) - return AVERROR(ENOMEM); - rt->flv_data = cp; - bytestream2_init_writer(&pbc, cp, rt->flv_size); - bytestream2_skip_p(&pbc, old_flv_size); - bytestream2_put_byte(&pbc, pkt->type); - bytestream2_put_be24(&pbc, datatowritelength); - bytestream2_put_be24(&pbc, ts); - bytestream2_put_byte(&pbc, ts >> 24); - bytestream2_put_be24(&pbc, 0); - bytestream2_put_buffer(&pbc, datatowrite, datatowritelength); - bytestream2_put_be32(&pbc, 0); - return 0; } @@ -2186,7 +2180,6 @@ static int get_packet(URLContext *s, int for_header) { RTMPContext *rt = s->priv_data; int ret; - uint8_t *p; const uint8_t *next; uint32_t size; uint32_t ts, cts, pts=0; @@ -2250,19 +2243,21 @@ static int get_packet(URLContext *s, int for_header) if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO || (rpkt.type == RTMP_PT_NOTIFY && ff_amf_match_string(rpkt.data, rpkt.size, "onMetaData"))) { + int err; ts = rpkt.timestamp; // generate packet header and put data into buffer for FLV demuxer rt->flv_off = 0; rt->flv_size = rpkt.size + 15; - rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size); - bytestream_put_byte(&p, rpkt.type); - bytestream_put_be24(&p, rpkt.size); - bytestream_put_be24(&p, ts); - bytestream_put_byte(&p, ts >> 24); - bytestream_put_be24(&p, 0); - bytestream_put_buffer(&p, rpkt.data, rpkt.size); - bytestream_put_be32(&p, 0); + if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0) + return err; + bytestream_put_byte(&rt->flv_data, rpkt.type); + bytestream_put_be24(&rt->flv_data, rpkt.size); + bytestream_put_be24(&rt->flv_data, ts); + bytestream_put_byte(&rt->flv_data, ts >> 24); + bytestream_put_be24(&rt->flv_data, 0); + bytestream_put_buffer(&rt->flv_data, rpkt.data, rpkt.size); + bytestream_put_be32(&rt->flv_data, 0); ff_rtmp_packet_destroy(&rpkt); return 0; } else if (rpkt.type == RTMP_PT_NOTIFY) { @@ -2274,10 +2269,13 @@ static int get_packet(URLContext *s, int for_header) } return 0; } else if (rpkt.type == RTMP_PT_METADATA) { + int err; + uint8_t *p; // we got raw FLV data, make it available for FLV demuxer rt->flv_off = 0; rt->flv_size = rpkt.size; - rt->flv_data = av_realloc(rt->flv_data, rt->flv_size); + if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0) + return err; /* rewrite timestamps */ next = rpkt.data; ts = rpkt.timestamp; @@ -2550,9 +2548,11 @@ reconnect: } if (rt->is_input) { + int err; // generate FLV header for demuxer rt->flv_size = 13; - rt->flv_data = av_realloc(rt->flv_data, rt->flv_size); + if ((err = av_reallocp(&rt->flv_data, rt->flv_size)) < 0) + return err; rt->flv_off = 0; memcpy(rt->flv_data, "FLV\1\5\0\0\0\011\0\0\0\0", rt->flv_size); } else { |