diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-05-25 20:48:50 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-05-25 21:06:14 +0200 |
commit | c0b47d1914a19abacdf1edf081cbf07485952920 (patch) | |
tree | 94b26fadd3ecf4352ff87bd807ea6124bc2f4c02 /libavformat | |
parent | e02e58fb1c108dd96ef5b61454a2ba8d2af895ea (diff) | |
parent | ed7bdd8647a3d0f534c2af0d244fc8744ff262a0 (diff) | |
download | ffmpeg-cbdd180493af4c5c071f776c1ae41739a8a6d977.tar.gz |
Merge remote-tracking branch 'qatar/master'n0.12-dev
* qatar/master:
movenc: Don't write the 'wave' atom or its child 'enda' for lpcm audio.
imc: some cosmetics
rtmp: Pass the proper return code in rtmp_handshake
rtmp: Check return codes of net IO operations
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/movenc.c | 2 | ||||
-rw-r--r-- | libavformat/rtmppkt.c | 15 | ||||
-rw-r--r-- | libavformat/rtmpproto.c | 98 |
3 files changed, 76 insertions, 39 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 752d52713a..aaf8152cf7 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -680,7 +680,7 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) track->enc->codec_id == CODEC_ID_ALAC || track->enc->codec_id == CODEC_ID_ADPCM_MS || track->enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || - mov_pcm_le_gt16(track->enc->codec_id))) + (mov_pcm_le_gt16(track->enc->codec_id) && version==1))) mov_write_wave_tag(pb, track); else if(track->tag == MKTAG('m','p','4','a')) mov_write_esds_tag(pb, track); diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index bca4a9dab6..f0efa59257 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -151,7 +151,10 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, offset += chunk_size; size += chunk_size; if (data_size > 0) { - ffurl_read_complete(h, &t, 1); //marker + if ((ret = ffurl_read_complete(h, &t, 1)) < 0) { // marker + ff_rtmp_packet_destroy(p); + return ret; + } size++; if (t != (0xC0 + channel_id)) return -1; @@ -167,6 +170,7 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, int mode = RTMP_PS_TWELVEBYTES; int off = 0; int size = 0; + int ret; pkt->ts_delta = pkt->timestamp - prev_pkt[pkt->channel_id].timestamp; @@ -218,15 +222,18 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, } prev_pkt[pkt->channel_id].extra = pkt->extra; - ffurl_write(h, pkt_hdr, p-pkt_hdr); + if ((ret = ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0) + return ret; size = p - pkt_hdr + pkt->data_size; while (off < pkt->data_size) { int towrite = FFMIN(chunk_size, pkt->data_size - off); - ffurl_write(h, pkt->data + off, towrite); + if ((ret = ffurl_write(h, pkt->data + off, towrite)) < 0) + return ret; off += towrite; if (off < pkt->data_size) { uint8_t marker = 0xC0 | pkt->channel_id; - ffurl_write(h, &marker, 1); + if ((ret = ffurl_write(h, &marker, 1)) < 0) + return ret; size++; } } diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index fdba429ab2..0f643e6c8a 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -167,10 +167,11 @@ static int gen_connect(URLContext *s, RTMPContext *rt) pkt.data_size = p - pkt.data; - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -194,10 +195,11 @@ static int gen_release_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_string(&p, rt->playpath); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -221,10 +223,11 @@ static int gen_fcpublish_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_string(&p, rt->playpath); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -248,10 +251,11 @@ static int gen_fcunpublish_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_string(&p, rt->playpath); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -276,10 +280,11 @@ static int gen_create_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); rt->create_stream_invoke = rt->nb_invokes; - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } @@ -305,10 +310,11 @@ static int gen_delete_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_number(&p, rt->main_channel_id); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -336,9 +342,13 @@ static int gen_play(URLContext *s, RTMPContext *rt) ff_amf_write_string(&p, rt->playpath); ff_amf_write_number(&p, rt->live); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); + if (ret < 0) + return ret; + // set client buffer time disguised in ping packet if ((ret = ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, 1, 10)) < 0) @@ -349,10 +359,11 @@ static int gen_play(URLContext *s, RTMPContext *rt) bytestream_put_be32(&p, 1); bytestream_put_be32(&p, 256); //TODO: what is a good value here? - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -379,7 +390,8 @@ static int gen_publish(URLContext *s, RTMPContext *rt) ff_amf_write_string(&p, rt->playpath); ff_amf_write_string(&p, "live"); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); return ret; @@ -401,10 +413,11 @@ static int gen_pong(URLContext *s, RTMPContext *rt, RTMPPacket *ppkt) p = pkt.data; bytestream_put_be16(&p, 7); bytestream_put_be32(&p, AV_RB32(ppkt->data+2)); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -422,10 +435,11 @@ static int gen_server_bw(URLContext *s, RTMPContext *rt) p = pkt.data; bytestream_put_be32(&p, 2500000); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } /** @@ -446,7 +460,8 @@ static int gen_check_bw(URLContext *s, RTMPContext *rt) ff_amf_write_number(&p, ++rt->nb_invokes); ff_amf_write_null(&p); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); return ret; @@ -467,10 +482,11 @@ static int gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts) p = pkt.data; bytestream_put_be32(&p, rt->bytes_read); - ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - return 0; + return ret; } //TODO: Move HMAC code somewhere. Eventually. @@ -617,16 +633,22 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) if (client_pos < 0) return client_pos; - ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); - i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); - if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) { + if ((ret = ffurl_write(rt->stream, tosend, + RTMP_HANDSHAKE_PACKET_SIZE + 1)) < 0) { + av_log(s, AV_LOG_ERROR, "Cannot write RTMP handshake request\n"); + return ret; + } + + if ((ret = ffurl_read_complete(rt->stream, serverdata, + RTMP_HANDSHAKE_PACKET_SIZE + 1)) < 0) { av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); - return AVERROR(EIO); + return ret; } - i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE); - if (i != RTMP_HANDSHAKE_PACKET_SIZE) { + + if ((ret = ffurl_read_complete(rt->stream, clientdata, + RTMP_HANDSHAKE_PACKET_SIZE)) < 0) { av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); - return AVERROR(EIO); + return ret; } av_log(s, AV_LOG_DEBUG, "Server version %d.%d.%d.%d\n", @@ -678,9 +700,13 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) return ret; // write reply back to the server - ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); + if ((ret = ffurl_write(rt->stream, tosend, + RTMP_HANDSHAKE_PACKET_SIZE)) < 0) + return ret; } else { - ffurl_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE); + if ((ret = ffurl_write(rt->stream, serverdata + 1, + RTMP_HANDSHAKE_PACKET_SIZE)) < 0) + return ret; } return 0; @@ -710,7 +736,9 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) return -1; } if (!rt->is_input) - ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size, rt->prev_pkt[1]); + if ((ret = ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size, + rt->prev_pkt[1])) < 0) + return ret; rt->chunk_size = AV_RB32(pkt->data); if (rt->chunk_size <= 0) { av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size); @@ -1201,7 +1229,9 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size) if (rt->flv_off == rt->flv_size) { rt->skip_bytes = 4; - ff_rtmp_packet_write(rt->stream, &rt->out_pkt, rt->chunk_size, rt->prev_pkt[1]); + if ((ret = ff_rtmp_packet_write(rt->stream, &rt->out_pkt, + rt->chunk_size, rt->prev_pkt[1])) < 0) + return ret; ff_rtmp_packet_destroy(&rt->out_pkt); rt->flv_size = 0; rt->flv_off = 0; |