diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-12-02 00:51:11 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-12-02 00:51:11 +0100 |
commit | 7b0b10ce4186eaa1cd3c0a2bfbb86307d65eecfd (patch) | |
tree | a9a937af698ca14ef06ec2c07453f474aa5ca3c7 /libavformat | |
parent | 8b08f81949bcfa6fec42ff3f1c9bef5be8140300 (diff) | |
parent | 04403ec2e405a3cfcfbdd45f1274be30c652e462 (diff) | |
download | ffmpeg-7b0b10ce4186eaa1cd3c0a2bfbb86307d65eecfd.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (25 commits)
rtpenc: Add support for G726 audio
rtpdec: Interpret the different G726 names as bits_per_coded_sample
rtpenc: Change rtp_send_samples to handle sample sizes other than even bytes
rtpenc: Cast a rescaling parameter to int64_t
h264: cap max has_b_frames at MAX_DELAYED_PIC_COUNT - 1.
ARM: fix indentation in ff_dsputil_init_neon()
ARM: NEON put/avg_pixels8/16 cosmetics
ARM: add remaining NEON avg_pixels8/16 functions
ARM: clean up NEON put/avg_pixels macros
fate: split acodec-pcm into individual tests
swscale: #include "libavutil/mathematics.h"
pmpdec: don't use deprecated av_set_pts_info.
rv34: align temporary block of "dct" coefs
Add PlayStation Portable PMP format demuxer
proto: Realign struct initializers
proto: Use .priv_data_size to allocate the private context
mmsh: Properly clean up if the second ffurl_alloc failed
rtmp: Clean up properly if the handshake failed
md5proto: Remove the get_file_handle function
applehttpproto: Use the close function if the open function fails
...
Conflicts:
libavcodec/vble.c
libavformat/mmsh.c
libavformat/pmpdec.c
libavformat/udp.c
tests/ref/acodec/pcm
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/applehttpproto.c | 40 | ||||
-rw-r--r-- | libavformat/cache.c | 11 | ||||
-rw-r--r-- | libavformat/concat.c | 20 | ||||
-rw-r--r-- | libavformat/gopher.c | 20 | ||||
-rw-r--r-- | libavformat/http.c | 2 | ||||
-rw-r--r-- | libavformat/librtmp.c | 24 | ||||
-rw-r--r-- | libavformat/md5proto.c | 5 | ||||
-rw-r--r-- | libavformat/mmsh.c | 23 | ||||
-rw-r--r-- | libavformat/mmst.c | 15 | ||||
-rw-r--r-- | libavformat/pmpdec.c | 19 | ||||
-rw-r--r-- | libavformat/rtmpproto.c | 20 | ||||
-rw-r--r-- | libavformat/rtpdec_g726.c | 6 | ||||
-rw-r--r-- | libavformat/rtpenc.c | 28 | ||||
-rw-r--r-- | libavformat/rtpproto.c | 10 | ||||
-rw-r--r-- | libavformat/sdp.c | 8 | ||||
-rw-r--r-- | libavformat/tcp.c | 10 | ||||
-rw-r--r-- | libavformat/udp.c | 10 |
17 files changed, 116 insertions, 155 deletions
diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c index 8218c0e05f..8295ccc5f5 100644 --- a/libavformat/applehttpproto.c +++ b/libavformat/applehttpproto.c @@ -174,19 +174,25 @@ fail: return ret; } +static int applehttp_close(URLContext *h) +{ + AppleHTTPContext *s = h->priv_data; + + free_segment_list(s); + free_variant_list(s); + ffurl_close(s->seg_hd); + return 0; +} + static int applehttp_open(URLContext *h, const char *uri, int flags) { - AppleHTTPContext *s; + AppleHTTPContext *s = h->priv_data; int ret, i; const char *nested_url; if (flags & AVIO_FLAG_WRITE) return AVERROR(ENOSYS); - s = av_mallocz(sizeof(AppleHTTPContext)); - if (!s) - return AVERROR(ENOMEM); - h->priv_data = s; h->is_streamed = 1; if (av_strstart(uri, "applehttp+", &nested_url)) { @@ -229,7 +235,7 @@ static int applehttp_open(URLContext *h, const char *uri, int flags) return 0; fail: - av_free(s); + applehttp_close(h); return ret; } @@ -287,21 +293,11 @@ retry: goto start; } -static int applehttp_close(URLContext *h) -{ - AppleHTTPContext *s = h->priv_data; - - free_segment_list(s); - free_variant_list(s); - ffurl_close(s->seg_hd); - av_free(s); - return 0; -} - URLProtocol ff_applehttp_protocol = { - .name = "applehttp", - .url_open = applehttp_open, - .url_read = applehttp_read, - .url_close = applehttp_close, - .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME, + .name = "applehttp", + .url_open = applehttp_open, + .url_read = applehttp_read, + .url_close = applehttp_close, + .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME, + .priv_data_size = sizeof(AppleHTTPContext), }; diff --git a/libavformat/cache.c b/libavformat/cache.c index c2bddf5f6d..d94cf5fbac 100644 --- a/libavformat/cache.c +++ b/libavformat/cache.c @@ -53,13 +53,7 @@ static int cache_open(URLContext *h, const char *arg, int flags) { int access; const char *buffername; - Context *c; - - c = av_mallocz(sizeof(Context)); - if (!c) { - return AVERROR(ENOMEM); - } - h->priv_data = c; + Context *c= h->priv_data; av_strstart(arg, "cache:", &arg); @@ -130,8 +124,6 @@ static int cache_close(URLContext *h) close(c->fd); ffurl_close(c->inner); - av_freep(&h->priv_data); - return 0; } @@ -141,4 +133,5 @@ URLProtocol ff_cache_protocol = { .url_read = cache_read, .url_seek = cache_seek, .url_close = cache_close, + .priv_data_size = sizeof(Context), }; diff --git a/libavformat/concat.c b/libavformat/concat.c index 81f37383b9..f97354c788 100644 --- a/libavformat/concat.c +++ b/libavformat/concat.c @@ -50,7 +50,6 @@ static av_cold int concat_close(URLContext *h) err |= ffurl_close(nodes[i].uc); av_freep(&data->nodes); - av_freep(&h->priv_data); return err < 0 ? -1 : 0; } @@ -62,16 +61,11 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) int64_t size; size_t len, i; URLContext *uc; - struct concat_data *data; + struct concat_data *data = h->priv_data; struct concat_nodes *nodes; av_strstart(uri, "concat:", &uri); - /* creating data */ - if (!(data = av_mallocz(sizeof(*data)))) - return AVERROR(ENOMEM); - h->priv_data = data; - for (i = 0, len = 1; uri[i]; i++) if (uri[i] == *AV_CAT_SEPARATOR) /* integer overflow */ @@ -81,7 +75,6 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) } if (!(nodes = av_malloc(sizeof(*nodes) * len))) { - av_freep(&h->priv_data); return AVERROR(ENOMEM); } else data->nodes = nodes; @@ -191,9 +184,10 @@ static int64_t concat_seek(URLContext *h, int64_t pos, int whence) } URLProtocol ff_concat_protocol = { - .name = "concat", - .url_open = concat_open, - .url_read = concat_read, - .url_seek = concat_seek, - .url_close = concat_close, + .name = "concat", + .url_open = concat_open, + .url_read = concat_read, + .url_seek = concat_seek, + .url_close = concat_close, + .priv_data_size = sizeof(struct concat_data), }; diff --git a/libavformat/gopher.c b/libavformat/gopher.c index 6a829c8ce5..e1acf5039c 100644 --- a/libavformat/gopher.c +++ b/libavformat/gopher.c @@ -72,24 +72,17 @@ static int gopher_close(URLContext *h) ffurl_close(s->hd); s->hd = NULL; } - av_freep(&h->priv_data); return 0; } static int gopher_open(URLContext *h, const char *uri, int flags) { - GopherContext *s; + GopherContext *s = h->priv_data; char hostname[1024], auth[1024], path[1024], buf[1024]; int port, err; h->is_streamed = 1; - s = av_malloc(sizeof(GopherContext)); - if (!s) { - return AVERROR(ENOMEM); - } - h->priv_data = s; - /* needed in any case to build the host string */ av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, path, sizeof(path), uri); @@ -122,9 +115,10 @@ static int gopher_read(URLContext *h, uint8_t *buf, int size) URLProtocol ff_gopher_protocol = { - .name = "gopher", - .url_open = gopher_open, - .url_read = gopher_read, - .url_write = gopher_write, - .url_close = gopher_close, + .name = "gopher", + .url_open = gopher_open, + .url_read = gopher_read, + .url_write = gopher_write, + .url_close = gopher_close, + .priv_data_size = sizeof(GopherContext), }; diff --git a/libavformat/http.c b/libavformat/http.c index 2e4e8c235d..f7e0b5cc8c 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -93,7 +93,7 @@ static int http_open_cnx(URLContext *h) { const char *path, *proxy_path, *lower_proto = "tcp", *local_path; char hostname[1024], hoststr[1024], proto[10]; - char auth[1024], proxyauth[1024]; + char auth[1024], proxyauth[1024] = ""; char path1[1024]; char buf[1024], urlbuf[1024]; int port, use_proxy, err, location_changed = 0, redirects = 0; diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c index 01b6c3deb0..018ea0f4b0 100644 --- a/libavformat/librtmp.c +++ b/libavformat/librtmp.c @@ -52,7 +52,6 @@ static int rtmp_close(URLContext *s) RTMP *r = s->priv_data; RTMP_Close(r); - av_free(r); return 0; } @@ -70,13 +69,9 @@ static int rtmp_close(URLContext *s) */ static int rtmp_open(URLContext *s, const char *uri, int flags) { - RTMP *r; + RTMP *r = s->priv_data; int rc; - r = av_mallocz(sizeof(RTMP)); - if (!r) - return AVERROR(ENOMEM); - switch (av_log_get_level()) { default: case AV_LOG_FATAL: rc = RTMP_LOGCRIT; break; @@ -103,11 +98,9 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) goto fail; } - s->priv_data = r; s->is_streamed = 1; return 0; fail: - av_free(r); return rc; } @@ -167,7 +160,8 @@ URLProtocol ff_rtmp_protocol = { .url_close = rtmp_close, .url_read_pause = rtmp_read_pause, .url_read_seek = rtmp_read_seek, - .url_get_file_handle = rtmp_get_file_handle + .url_get_file_handle = rtmp_get_file_handle, + .priv_data_size = sizeof(RTMP), }; URLProtocol ff_rtmpt_protocol = { @@ -178,7 +172,8 @@ URLProtocol ff_rtmpt_protocol = { .url_close = rtmp_close, .url_read_pause = rtmp_read_pause, .url_read_seek = rtmp_read_seek, - .url_get_file_handle = rtmp_get_file_handle + .url_get_file_handle = rtmp_get_file_handle, + .priv_data_size = sizeof(RTMP), }; URLProtocol ff_rtmpe_protocol = { @@ -189,7 +184,8 @@ URLProtocol ff_rtmpe_protocol = { .url_close = rtmp_close, .url_read_pause = rtmp_read_pause, .url_read_seek = rtmp_read_seek, - .url_get_file_handle = rtmp_get_file_handle + .url_get_file_handle = rtmp_get_file_handle, + .priv_data_size = sizeof(RTMP), }; URLProtocol ff_rtmpte_protocol = { @@ -200,7 +196,8 @@ URLProtocol ff_rtmpte_protocol = { .url_close = rtmp_close, .url_read_pause = rtmp_read_pause, .url_read_seek = rtmp_read_seek, - .url_get_file_handle = rtmp_get_file_handle + .url_get_file_handle = rtmp_get_file_handle, + .priv_data_size = sizeof(RTMP), }; URLProtocol ff_rtmps_protocol = { @@ -211,5 +208,6 @@ URLProtocol ff_rtmps_protocol = { .url_close = rtmp_close, .url_read_pause = rtmp_read_pause, .url_read_seek = rtmp_read_seek, - .url_get_file_handle = rtmp_get_file_handle + .url_get_file_handle = rtmp_get_file_handle, + .priv_data_size = sizeof(RTMP), }; diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c index 05ee9d366a..f7c8b78fee 100644 --- a/libavformat/md5proto.c +++ b/libavformat/md5proto.c @@ -79,16 +79,11 @@ static int md5_close(URLContext *h) return err; } -static int md5_get_handle(URLContext *h) -{ - return (intptr_t)h->priv_data; -} URLProtocol ff_md5_protocol = { .name = "md5", .url_open = md5_open, .url_write = md5_write, .url_close = md5_close, - .url_get_file_handle = md5_get_handle, .priv_data_size = PRIV_SIZE, }; diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c index bc93722f1a..e92b74fc0a 100644 --- a/libavformat/mmsh.c +++ b/libavformat/mmsh.c @@ -69,7 +69,6 @@ static int mmsh_close(URLContext *h) ffurl_close(mms->mms_hd); av_free(mms->streams); av_free(mms->asf_header); - av_freep(&h->priv_data); return 0; } @@ -218,12 +217,9 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim char httpname[256], path[256], host[128]; char *stream_selection = NULL; char headers[1024]; - MMSHContext *mmsh; + MMSHContext *mmsh = h->priv_data; MMSContext *mms; - mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext)); - if (!h->priv_data) - return AVERROR(ENOMEM); mmsh->request_seq = h->is_streamed = 1; mms = &mmsh->mms; av_strlcpy(mmsh->location, uri, sizeof(mmsh->location)); @@ -263,9 +259,9 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim // close the socket and then reopen it for sending the second play request. ffurl_close(mms->mms_hd); memset(headers, 0, sizeof(headers)); - if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ, - &h->interrupt_callback) < 0) { - return AVERROR(EIO); + if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ, + &h->interrupt_callback)) < 0) { + goto fail; } stream_selection = av_mallocz(mms->stream_num * 19 + 1); if (!stream_selection) @@ -403,10 +399,11 @@ static int64_t mmsh_seek(URLContext *h, int64_t pos, int whence) } URLProtocol ff_mmsh_protocol = { - .name = "mmsh", - .url_open = mmsh_open, - .url_read = mmsh_read, - .url_seek = mmsh_seek, - .url_close = mmsh_close, + .name = "mmsh", + .url_open = mmsh_open, + .url_read = mmsh_read, + .url_seek = mmsh_seek, + .url_close = mmsh_close, .url_read_seek = mmsh_read_seek, + .priv_data_size = sizeof(MMSHContext), }; diff --git a/libavformat/mmst.c b/libavformat/mmst.c index 0a728eb35f..a6fe696f5f 100644 --- a/libavformat/mmst.c +++ b/libavformat/mmst.c @@ -470,7 +470,6 @@ static int mms_close(URLContext *h) /* free all separately allocated pointers in mms */ av_free(mms->streams); av_free(mms->asf_header); - av_freep(&h->priv_data); return 0; } @@ -502,15 +501,12 @@ static void clear_stream_buffers(MMSContext *mms) static int mms_open(URLContext *h, const char *uri, int flags) { - MMSTContext *mmst; + MMSTContext *mmst = h->priv_data; MMSContext *mms; int port, err; char tcpname[256]; h->is_streamed = 1; - mmst = h->priv_data = av_mallocz(sizeof(MMSTContext)); - if (!h->priv_data) - return AVERROR(ENOMEM); mms = &mmst->mms; // only for MMS over TCP, so set proto = NULL @@ -624,8 +620,9 @@ static int mms_read(URLContext *h, uint8_t *buf, int size) } URLProtocol ff_mmst_protocol = { - .name = "mmst", - .url_open = mms_open, - .url_read = mms_read, - .url_close = mms_close, + .name = "mmst", + .url_open = mms_open, + .url_read = mms_read, + .url_close = mms_close, + .priv_data_size = sizeof(MMSTContext), }; diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c index 88b8998ad9..3d54484314 100644 --- a/libavformat/pmpdec.c +++ b/libavformat/pmpdec.c @@ -38,7 +38,8 @@ static int pmp_probe(AVProbeData *p) { return 0; } -static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) { +static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) +{ PMPContext *pmp = s->priv_data; AVIOContext *pb = s->pb; int tb_num, tb_den; @@ -93,7 +94,6 @@ static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) { AVStream *ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ast->id = i; ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_id = audio_codec_id; ast->codec->channels = channels; @@ -111,7 +111,8 @@ static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) { return 0; } -static int pmp_packet(AVFormatContext *s, AVPacket *pkt) { +static int pmp_packet(AVFormatContext *s, AVPacket *pkt) +{ PMPContext *pmp = s->priv_data; AVIOContext *pb = s->pb; int ret = 0; @@ -128,14 +129,18 @@ static int pmp_packet(AVFormatContext *s, AVPacket *pkt) { av_fast_malloc(&pmp->packet_sizes, &pmp->packet_sizes_alloc, num_packets * sizeof(*pmp->packet_sizes)); + if (!pmp->packet_sizes_alloc) { + av_log(s, AV_LOG_ERROR, "Cannot (re)allocate packet buffer\n"); + return AVERROR(ENOMEM); + } for (i = 0; i < num_packets; i++) pmp->packet_sizes[i] = avio_rl32(pb); } ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]); if (ret >= 0) { ret = 0; - // FIXME: this is a hack that should be remove once - // compute_pkt_fields can handle + // FIXME: this is a hack that should be removed once + // compute_pkt_fields() can handle timestamps properly if (pmp->cur_stream == 0) pkt->dts = s->streams[0]->cur_dts++; pkt->stream_index = pmp->cur_stream; @@ -146,8 +151,8 @@ static int pmp_packet(AVFormatContext *s, AVPacket *pkt) { return ret; } -static int pmp_seek(AVFormatContext *s, int stream_index, - int64_t ts, int flags) { +static int pmp_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags) +{ PMPContext *pmp = s->priv_data; pmp->cur_stream = 0; // fallback to default seek now diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 8935f56369..8f57d1bb59 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -784,7 +784,6 @@ static int rtmp_close(URLContext *h) av_freep(&rt->flv_data); ffurl_close(rt->stream); - av_free(rt); return 0; } @@ -799,16 +798,12 @@ static int rtmp_close(URLContext *h) */ static int rtmp_open(URLContext *s, const char *uri, int flags) { - RTMPContext *rt; + RTMPContext *rt = s->priv_data; char proto[8], hostname[256], path[1024], *fname; uint8_t buf[2048]; int port; int ret; - rt = av_mallocz(sizeof(RTMPContext)); - if (!rt) - return AVERROR(ENOMEM); - s->priv_data = rt; rt->is_input = !(flags & AVIO_FLAG_WRITE); av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, @@ -826,7 +821,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) rt->state = STATE_START; if (rtmp_handshake(s, rt)) - return -1; + goto fail; rt->chunk_size = 128; rt->state = STATE_HANDSHAKED; @@ -997,9 +992,10 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size) } URLProtocol ff_rtmp_protocol = { - .name = "rtmp", - .url_open = rtmp_open, - .url_read = rtmp_read, - .url_write = rtmp_write, - .url_close = rtmp_close, + .name = "rtmp", + .url_open = rtmp_open, + .url_read = rtmp_read, + .url_write = rtmp_write, + .url_close = rtmp_close, + .priv_data_size = sizeof(RTMPContext), }; diff --git a/libavformat/rtpdec_g726.c b/libavformat/rtpdec_g726.c index 35ca9061fd..20450d8dfb 100644 --- a/libavformat/rtpdec_g726.c +++ b/libavformat/rtpdec_g726.c @@ -27,10 +27,8 @@ static int g726_ ## bitrate ##_init(AVFormatContext *s, int st_index, PayloadCon AVStream *stream = s->streams[st_index]; \ AVCodecContext *codec = stream->codec; \ \ - codec->bit_rate = bitrate*1000; \ - if (codec->sample_rate) \ - codec->bits_per_coded_sample = \ - av_clip((codec->bit_rate + codec->sample_rate/2) / codec->sample_rate, 2, 5); \ + codec->bits_per_coded_sample = bitrate/8; \ + codec->bit_rate = codec->bits_per_coded_sample * codec->sample_rate; \ \ return 0; \ } \ diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 73ac76fae7..ac9b32cc0c 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -72,6 +72,7 @@ static int is_supported(enum CodecID id) case CODEC_ID_THEORA: case CODEC_ID_VP8: case CODEC_ID_ADPCM_G722: + case CODEC_ID_ADPCM_G726: return 1; default: return 0; @@ -121,7 +122,7 @@ static int rtp_write_header(AVFormatContext *s1) if (st->codec->frame_size == 0) { av_log(s1, AV_LOG_ERROR, "Cannot respect max delay: frame size = 0\n"); } else { - s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * st->codec->frame_size, AV_ROUND_DOWN); + s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * (int64_t)st->codec->frame_size, AV_ROUND_DOWN); } } if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -248,14 +249,16 @@ void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m) /* send an integer number of samples and compute time stamp and fill the rtp send buffer before sending. */ static void rtp_send_samples(AVFormatContext *s1, - const uint8_t *buf1, int size, int sample_size) + const uint8_t *buf1, int size, int sample_size_bits) { RTPMuxContext *s = s1->priv_data; int len, max_packet_size, n; + /* Calculate the number of bytes to get samples aligned on a byte border */ + int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8); - max_packet_size = (s->max_payload_size / sample_size) * sample_size; - /* not needed, but who nows */ - if ((size % sample_size) != 0) + max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size; + /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */ + if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0) av_abort(); n = 0; while (size > 0) { @@ -267,7 +270,7 @@ static void rtp_send_samples(AVFormatContext *s1, s->buf_ptr += len; buf1 += len; size -= len; - s->timestamp = s->cur_timestamp + n / sample_size; + s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits; ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); n += (s->buf_ptr - s->buf); } @@ -394,19 +397,24 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_U8: case CODEC_ID_PCM_S8: - rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels); + rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); break; case CODEC_ID_PCM_U16BE: case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_S16LE: - rtp_send_samples(s1, pkt->data, size, 2 * st->codec->channels); + rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels); break; case CODEC_ID_ADPCM_G722: /* The actual sample size is half a byte per sample, but since the * stream clock rate is 8000 Hz while the sample rate is 16000 Hz, - * the correct parameter for send_samples is 1 byte per stream clock. */ - rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels); + * the correct parameter for send_samples_bits is 8 bits per stream + * clock. */ + rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); + break; + case CODEC_ID_ADPCM_G726: + rtp_send_samples(s1, pkt->data, size, + st->codec->bits_per_coded_sample * st->codec->channels); break; case CODEC_ID_MP2: case CODEC_ID_MP3: diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 41fb7317bb..b6f2a56146 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -137,7 +137,7 @@ static void build_udp_url(char *buf, int buf_size, static int rtp_open(URLContext *h, const char *uri, int flags) { - RTPContext *s; + RTPContext *s = h->priv_data; int rtp_port, rtcp_port, ttl, connect, local_rtp_port, local_rtcp_port, max_packet_size; @@ -146,11 +146,6 @@ static int rtp_open(URLContext *h, const char *uri, int flags) char path[1024]; const char *p; - s = av_mallocz(sizeof(RTPContext)); - if (!s) - return AVERROR(ENOMEM); - h->priv_data = s; - av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port, path, sizeof(path), uri); /* extract parameters */ @@ -214,7 +209,6 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ffurl_close(s->rtp_hd); if (s->rtcp_hd) ffurl_close(s->rtcp_hd); - av_free(s); return AVERROR(EIO); } @@ -291,7 +285,6 @@ static int rtp_close(URLContext *h) ffurl_close(s->rtp_hd); ffurl_close(s->rtcp_hd); - av_free(s); return 0; } @@ -337,4 +330,5 @@ URLProtocol ff_rtp_protocol = { .url_write = rtp_write, .url_close = rtp_close, .url_get_file_handle = rtp_get_file_handle, + .priv_data_size = sizeof(RTPContext), }; diff --git a/libavformat/sdp.c b/libavformat/sdp.c index 13c5ba6629..5def15d2a3 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -517,6 +517,14 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, payload_type, 8000, c->channels); break; + case CODEC_ID_ADPCM_G726: { + if (payload_type >= RTP_PT_PRIVATE) + av_strlcatf(buff, size, "a=rtpmap:%d G726-%d/%d\r\n", + payload_type, + c->bits_per_coded_sample*8, + c->sample_rate); + break; + } default: /* Nothing special to do here... */ break; diff --git a/libavformat/tcp.c b/libavformat/tcp.c index f882fc0dee..1aeceb9e02 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -39,7 +39,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) { struct addrinfo hints, *ai, *cur_ai; int port, fd = -1; - TCPContext *s = NULL; + TCPContext *s = h->priv_data; int listen_socket = 0; const char *p; char buf[256]; @@ -135,12 +135,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags) goto fail; } } - s = av_malloc(sizeof(TCPContext)); - if (!s) { - freeaddrinfo(ai); - return AVERROR(ENOMEM); - } - h->priv_data = s; h->is_streamed = 1; s->fd = fd; freeaddrinfo(ai); @@ -193,7 +187,6 @@ static int tcp_close(URLContext *h) { TCPContext *s = h->priv_data; closesocket(s->fd); - av_free(s); return 0; } @@ -210,4 +203,5 @@ URLProtocol ff_tcp_protocol = { .url_write = tcp_write, .url_close = tcp_close, .url_get_file_handle = tcp_get_file_handle, + .priv_data_size = sizeof(TCPContext), }; diff --git a/libavformat/udp.c b/libavformat/udp.c index ee5b304769..a0d127c614 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -381,7 +381,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) { char hostname[1024], localaddr[1024] = ""; int port, udp_fd = -1, tmp, bind_ret = -1; - UDPContext *s = NULL; + UDPContext *s = h->priv_data; int is_output; const char *p; char buf[256]; @@ -394,11 +394,6 @@ static int udp_open(URLContext *h, const char *uri, int flags) is_output = !(flags & AVIO_FLAG_READ); - s = av_mallocz(sizeof(UDPContext)); - if (!s) - return AVERROR(ENOMEM); - - h->priv_data = s; s->ttl = 16; s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE; @@ -533,7 +528,6 @@ static int udp_open(URLContext *h, const char *uri, int flags) if (udp_fd >= 0) closesocket(udp_fd); av_fifo_free(s->fifo); - av_free(s); return AVERROR(EIO); } @@ -614,7 +608,6 @@ static int udp_close(URLContext *h) udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); closesocket(s->udp_fd); av_fifo_free(s->fifo); - av_free(s); return 0; } @@ -625,4 +618,5 @@ URLProtocol ff_udp_protocol = { .url_write = udp_write, .url_close = udp_close, .url_get_file_handle = udp_get_file_handle, + .priv_data_size = sizeof(UDPContext), }; |