summaryrefslogtreecommitdiff
path: root/libavformat/rtmpproto.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-09-23 00:23:10 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-09-23 00:35:31 +0200
commit28d3738428128d0bf16ff23995b08b3289179478 (patch)
treea45fc603df658badc2cb3eef0da0b340d409ca4a /libavformat/rtmpproto.c
parent6c4cc0f640874f6098ef98bad54c3fc0fa7c615f (diff)
parentdcb9f6a20dbddd1f95b6b322fc4c5fd0b5315729 (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: Add LATM demuxer avplay: flush audio decoder with empty packets at EOF if the decoder has CODEC_CAP_DELAY set. 8svx/iff: fix decoding of compressed stereo 8svx files. 8svx: log an error message if output buffer is too small 8svx: check packet size before reading the initial sample value. 8svx: output 8-bit samples instead of 16-bit. 8svx: split delta decoding into a separate function. mp4: Don't read an empty Decoder Config Descriptor fate.sh: Ignore errors from rm command during cleanup. fate.sh: Run git-pull in quiet mode to avoid console spam. Apple ProRes decoder rtmp: Make the input FLV parser handle data cut at any point rv34: Check for invalid slices offsets eval: test isnan(sqrt(-1)) instead of just sqrt(-1) Conflicts: Changelog libavcodec/8svx.c libavcodec/proresdec.c libavcodec/version.h libavformat/iff.c libavformat/version.h tests/ref/fate/eval Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/rtmpproto.c')
-rw-r--r--libavformat/rtmpproto.c61
1 files changed, 27 insertions, 34 deletions
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 920ca44c34..ed483cf37f 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -72,6 +72,8 @@ typedef struct RTMPContext {
uint32_t bytes_read; ///< number of bytes read from server
uint32_t last_bytes_read; ///< number of bytes read last reported to server
int skip_bytes; ///< number of bytes to skip from the input FLV stream in the next write call
+ uint8_t flv_header[11]; ///< partial incoming flv packet header
+ int flv_header_bytes; ///< number of initialized bytes in flv_header
} RTMPContext;
#define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing
@@ -880,6 +882,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
rt->flv_size = 0;
rt->flv_data = NULL;
rt->flv_off = 0;
+ rt->skip_bytes = 13;
}
s->max_packet_size = rt->stream->max_packet_size;
@@ -926,34 +929,29 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
uint32_t ts;
const uint8_t *buf_temp = buf;
- if (rt->skip_bytes) {
- int skip = FFMIN(rt->skip_bytes, size);
- buf_temp += skip;
- size_temp -= skip;
- rt->skip_bytes -= skip;
- if (size_temp <= 0)
- return size;
- }
-
- if (!rt->flv_off && size_temp < 11) {
- av_log(s, AV_LOG_DEBUG, "FLV packet too small %d\n", size);
- return 0;
- }
-
do {
- if (!rt->flv_off) {
- //skip flv header
- if (buf_temp[0] == 'F' && buf_temp[1] == 'L' && buf_temp[2] == 'V') {
- buf_temp += 9 + 4;
- size_temp -= 9 + 4;
- }
+ if (rt->skip_bytes) {
+ int skip = FFMIN(rt->skip_bytes, size_temp);
+ buf_temp += skip;
+ size_temp -= skip;
+ rt->skip_bytes -= skip;
+ continue;
+ }
+
+ if (rt->flv_header_bytes < 11) {
+ const uint8_t *header = rt->flv_header;
+ int copy = FFMIN(11 - rt->flv_header_bytes, size_temp);
+ bytestream_get_buffer(&buf_temp, rt->flv_header + rt->flv_header_bytes, copy);
+ rt->flv_header_bytes += copy;
+ size_temp -= copy;
+ if (rt->flv_header_bytes < 11)
+ break;
- pkttype = bytestream_get_byte(&buf_temp);
- pktsize = bytestream_get_be24(&buf_temp);
- ts = bytestream_get_be24(&buf_temp);
- ts |= bytestream_get_byte(&buf_temp) << 24;
- bytestream_get_be24(&buf_temp);
- size_temp -= 11;
+ pkttype = bytestream_get_byte(&header);
+ pktsize = bytestream_get_be24(&header);
+ ts = bytestream_get_be24(&header);
+ ts |= bytestream_get_byte(&header) << 24;
+ bytestream_get_be24(&header);
rt->flv_size = pktsize;
//force 12bytes header
@@ -984,18 +982,13 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
}
if (rt->flv_off == rt->flv_size) {
- if (size_temp < 4) {
- rt->skip_bytes = 4 - size_temp;
- buf_temp += size_temp;
- size_temp = 0;
- } else {
- bytestream_get_be32(&buf_temp);
- size_temp -= 4;
- }
+ rt->skip_bytes = 4;
+
ff_rtmp_packet_write(rt->stream, &rt->out_pkt, rt->chunk_size, rt->prev_pkt[1]);
ff_rtmp_packet_destroy(&rt->out_pkt);
rt->flv_size = 0;
rt->flv_off = 0;
+ rt->flv_header_bytes = 0;
}
} while (buf_temp - buf < size);
return size;