summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/Makefile6
-rw-r--r--libavformat/ffmenc.c5
-rw-r--r--libavformat/rtmpproto.c214
-rw-r--r--libavformat/swf.c29
-rw-r--r--libavformat/swf.h15
-rw-r--r--libavformat/swfdec.c11
-rw-r--r--libavformat/swfenc.c2
7 files changed, 168 insertions, 114 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile
index d77c9ea5eb..2994eef191 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -53,7 +53,7 @@ OBJS-$(CONFIG_AU_MUXER) += au.o
OBJS-$(CONFIG_AVI_DEMUXER) += avidec.o
OBJS-$(CONFIG_AVI_MUXER) += avienc.o
OBJS-$(CONFIG_AVISYNTH) += avisynth.o
-OBJS-$(CONFIG_AVM2_MUXER) += swfenc.o
+OBJS-$(CONFIG_AVM2_MUXER) += swfenc.o swf.o
OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o
OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o
OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o
@@ -326,8 +326,8 @@ OBJS-$(CONFIG_SRT_DEMUXER) += srtdec.o
OBJS-$(CONFIG_SRT_MUXER) += srtenc.o
OBJS-$(CONFIG_STR_DEMUXER) += psxstr.o
OBJS-$(CONFIG_SUBVIEWER_DEMUXER) += subviewerdec.o
-OBJS-$(CONFIG_SWF_DEMUXER) += swfdec.o
-OBJS-$(CONFIG_SWF_MUXER) += swfenc.o
+OBJS-$(CONFIG_SWF_DEMUXER) += swfdec.o swf.o
+OBJS-$(CONFIG_SWF_MUXER) += swfenc.o swf.o
OBJS-$(CONFIG_THP_DEMUXER) += thp.o
OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER) += tiertexseq.o
OBJS-$(CONFIG_MKVTIMESTAMP_V2_MUXER) += mkvtimestamp_v2.o
diff --git a/libavformat/ffmenc.c b/libavformat/ffmenc.c
index ca252dee08..6ce69cf8a9 100644
--- a/libavformat/ffmenc.c
+++ b/libavformat/ffmenc.c
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <assert.h>
+
#include "libavutil/intreadwrite.h"
#include "libavutil/intfloat.h"
#include "libavutil/avassert.h"
@@ -35,8 +37,7 @@ static void flush_packet(AVFormatContext *s)
fill_size = ffm->packet_end - ffm->packet_ptr;
memset(ffm->packet_ptr, 0, fill_size);
- if (avio_tell(pb) % ffm->packet_size)
- av_abort();
+ assert(avio_tell(pb) % ffm->packet_size == 0);
/* put header */
avio_wb16(pb, PACKET_ID);
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index e48c740a2e..5dae64118b 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -1021,121 +1021,149 @@ static int handle_server_bw(URLContext *s, RTMPPacket *pkt)
return 0;
}
-static int handle_invoke(URLContext *s, RTMPPacket *pkt)
+static int handle_invoke_error(URLContext *s, RTMPPacket *pkt)
{
- RTMPContext *rt = s->priv_data;
- int i, t;
const uint8_t *data_end = pkt->data + pkt->data_size;
+ uint8_t tmpstr[256];
+
+ if (!ff_amf_get_field_value(pkt->data + 9, data_end,
+ "description", tmpstr, sizeof(tmpstr))) {
+ av_log(s, AV_LOG_ERROR, "Server error: %s\n", tmpstr);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int handle_invoke_result(URLContext *s, RTMPPacket *pkt)
+{
+ RTMPContext *rt = s->priv_data;
char *tracked_method = NULL;
+ GetByteContext gbc;
+ double pkt_id;
int ret = 0;
+ int i;
- //TODO: check for the messages sent for wrong state?
- if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
- uint8_t tmpstr[256];
+ bytestream2_init(&gbc, pkt->data + 10, pkt->data_size);
+ if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0)
+ return ret;
- if (!ff_amf_get_field_value(pkt->data + 9, data_end,
- "description", tmpstr, sizeof(tmpstr)))
- av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
- return -1;
- } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
- GetByteContext gbc;
- double pkt_id;
+ for (i = 0; i < rt->nb_tracked_methods; i++) {
+ if (rt->tracked_methods[i].id != pkt_id)
+ continue;
- bytestream2_init(&gbc, pkt->data + 10, pkt->data_size);
- if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0)
- return ret;
+ tracked_method = rt->tracked_methods[i].name;
+ del_tracked_method(rt, i);
+ break;
+ }
- for (i = 0; i < rt->nb_tracked_methods; i++) {
- if (rt->tracked_methods[i].id != pkt_id)
- continue;
+ if (!tracked_method) {
+ /* Ignore this reply when the current method is not tracked. */
+ return ret;
+ }
- tracked_method = rt->tracked_methods[i].name;
- del_tracked_method(rt, i);
- break;
- }
+ if (!memcmp(tracked_method, "connect", 7)) {
+ if (!rt->is_input) {
+ if ((ret = gen_release_stream(s, rt)) < 0)
+ goto fail;
- if (!tracked_method) {
- /* Ignore this reply when the current method is not tracked. */
- return 0;
+ if ((ret = gen_fcpublish_stream(s, rt)) < 0)
+ goto fail;
+ } else {
+ if ((ret = gen_server_bw(s, rt)) < 0)
+ goto fail;
}
- if (!memcmp(tracked_method, "connect", 7)) {
- if (!rt->is_input) {
- if ((ret = gen_release_stream(s, rt)) < 0)
- goto invoke_fail;
-
- if ((ret = gen_fcpublish_stream(s, rt)) < 0)
- goto invoke_fail;
- } else {
- if ((ret = gen_server_bw(s, rt)) < 0)
- goto invoke_fail;
- }
-
- if ((ret = gen_create_stream(s, rt)) < 0)
- goto invoke_fail;
-
- if (rt->is_input) {
- /* Send the FCSubscribe command when the name of live
- * stream is defined by the user or if it's a live stream. */
- if (rt->subscribe) {
- if ((ret = gen_fcsubscribe_stream(s, rt,
- rt->subscribe)) < 0)
- goto invoke_fail;
- } else if (rt->live == -1) {
- if ((ret = gen_fcsubscribe_stream(s, rt,
- rt->playpath)) < 0)
- goto invoke_fail;
- }
- }
- } else if (!memcmp(tracked_method, "createStream", 12)) {
- //extract a number from the result
- if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) {
- av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n");
- } else {
- rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21));
- }
+ if ((ret = gen_create_stream(s, rt)) < 0)
+ goto fail;
- if (!rt->is_input) {
- if ((ret = gen_publish(s, rt)) < 0)
- goto invoke_fail;
- } else {
- if ((ret = gen_play(s, rt)) < 0)
- goto invoke_fail;
- if ((ret = gen_buffer_time(s, rt)) < 0)
- goto invoke_fail;
+ if (rt->is_input) {
+ /* Send the FCSubscribe command when the name of live
+ * stream is defined by the user or if it's a live stream. */
+ if (rt->subscribe) {
+ if ((ret = gen_fcsubscribe_stream(s, rt, rt->subscribe)) < 0)
+ goto fail;
+ } else if (rt->live == -1) {
+ if ((ret = gen_fcsubscribe_stream(s, rt, rt->playpath)) < 0)
+ goto fail;
}
}
- } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) {
- const uint8_t* ptr = pkt->data + 11;
- uint8_t tmpstr[256];
-
- for (i = 0; i < 2; i++) {
- t = ff_amf_tag_size(ptr, data_end);
- if (t < 0)
- return 1;
- ptr += t;
+ } else if (!memcmp(tracked_method, "createStream", 12)) {
+ //extract a number from the result
+ if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) {
+ av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n");
+ } else {
+ rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21));
}
- t = ff_amf_get_field_value(ptr, data_end,
- "level", tmpstr, sizeof(tmpstr));
- if (!t && !strcmp(tmpstr, "error")) {
- if (!ff_amf_get_field_value(ptr, data_end,
- "description", tmpstr, sizeof(tmpstr)))
- av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
- return -1;
+
+ if (!rt->is_input) {
+ if ((ret = gen_publish(s, rt)) < 0)
+ goto fail;
+ } else {
+ if ((ret = gen_play(s, rt)) < 0)
+ goto fail;
+ if ((ret = gen_buffer_time(s, rt)) < 0)
+ goto fail;
}
- t = ff_amf_get_field_value(ptr, data_end,
- "code", tmpstr, sizeof(tmpstr));
- if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING;
- if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED;
- if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED;
- if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING;
+ }
+
+fail:
+ av_free(tracked_method);
+ return ret;
+}
+
+static int handle_invoke_status(URLContext *s, RTMPPacket *pkt)
+{
+ RTMPContext *rt = s->priv_data;
+ const uint8_t *data_end = pkt->data + pkt->data_size;
+ const uint8_t *ptr = pkt->data + 11;
+ uint8_t tmpstr[256];
+ int i, t;
+
+ for (i = 0; i < 2; i++) {
+ t = ff_amf_tag_size(ptr, data_end);
+ if (t < 0)
+ return 1;
+ ptr += t;
+ }
+
+ t = ff_amf_get_field_value(ptr, data_end, "level", tmpstr, sizeof(tmpstr));
+ if (!t && !strcmp(tmpstr, "error")) {
+ if (!ff_amf_get_field_value(ptr, data_end,
+ "description", tmpstr, sizeof(tmpstr)))
+ av_log(s, AV_LOG_ERROR, "Server error: %s\n", tmpstr);
+ return -1;
+ }
+
+ t = ff_amf_get_field_value(ptr, data_end, "code", tmpstr, sizeof(tmpstr));
+ if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING;
+ if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED;
+ if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED;
+ if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING;
+
+ return 0;
+}
+
+static int handle_invoke(URLContext *s, RTMPPacket *pkt)
+{
+ RTMPContext *rt = s->priv_data;
+ int ret = 0;
+
+ //TODO: check for the messages sent for wrong state?
+ if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
+ if ((ret = handle_invoke_error(s, pkt)) < 0)
+ return ret;
+ } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
+ if ((ret = handle_invoke_result(s, pkt)) < 0)
+ return ret;
+ } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) {
+ if ((ret = handle_invoke_status(s, pkt)) < 0)
+ return ret;
} else if (!memcmp(pkt->data, "\002\000\010onBWDone", 11)) {
if ((ret = gen_check_bw(s, rt)) < 0)
return ret;
}
-invoke_fail:
- av_free(tracked_method);
return ret;
}
diff --git a/libavformat/swf.c b/libavformat/swf.c
new file mode 100644
index 0000000000..d0095077e5
--- /dev/null
+++ b/libavformat/swf.c
@@ -0,0 +1,29 @@
+/*
+ * Flash Compatible Streaming Format
+ * Copyright (c) 2000 Fabrice Bellard
+ * Copyright (c) 2003 Tinic Uro
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "internal.h"
+
+const AVCodecTag ff_swf_codec_tags[] = {
+ { CODEC_ID_FLV1, 0x02 },
+ { CODEC_ID_VP6F, 0x04 },
+ { CODEC_ID_NONE, 0 },
+};
diff --git a/libavformat/swf.h b/libavformat/swf.h
index 2f920f7dd3..3c0c6076f2 100644
--- a/libavformat/swf.h
+++ b/libavformat/swf.h
@@ -91,19 +91,6 @@ typedef struct {
#endif
} SWFContext;
-static const AVCodecTag swf_codec_tags[] = {
- { AV_CODEC_ID_FLV1, 0x02},
- { AV_CODEC_ID_VP6F, 0x04},
- { AV_CODEC_ID_NONE, 0},
-};
-
-static const AVCodecTag swf_audio_codec_tags[] = {
- { AV_CODEC_ID_PCM_S16LE, 0x00},
- { AV_CODEC_ID_ADPCM_SWF, 0x01},
- { AV_CODEC_ID_MP3, 0x02},
- { AV_CODEC_ID_PCM_S16LE, 0x03},
- //{ AV_CODEC_ID_NELLYMOSER, 0x06},
- { AV_CODEC_ID_NONE, 0},
-};
+extern const AVCodecTag ff_swf_codec_tags[];
#endif /* AVFORMAT_SWF_H */
diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
index 1e974fef69..069457f9fd 100644
--- a/libavformat/swfdec.c
+++ b/libavformat/swfdec.c
@@ -23,6 +23,15 @@
#include "libavutil/intreadwrite.h"
#include "swf.h"
+static const AVCodecTag swf_audio_codec_tags[] = {
+ { CODEC_ID_PCM_S16LE, 0x00 },
+ { CODEC_ID_ADPCM_SWF, 0x01 },
+ { CODEC_ID_MP3, 0x02 },
+ { CODEC_ID_PCM_S16LE, 0x03 },
+// { CODEC_ID_NELLYMOSER, 0x06 },
+ { CODEC_ID_NONE, 0 },
+};
+
static int get_swf_tag(AVIOContext *pb, int *len_ptr)
{
int tag, len;
@@ -164,7 +173,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
return -1;
vst->id = ch_id;
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, avio_r8(pb));
+ vst->codec->codec_id = ff_codec_get_id(ff_swf_codec_tags, avio_r8(pb));
avpriv_set_pts_info(vst, 16, 256, swf->frame_rate);
len -= 8;
} else if (tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) {
diff --git a/libavformat/swfenc.c b/libavformat/swfenc.c
index 3443da0ed2..862176953c 100644
--- a/libavformat/swfenc.c
+++ b/libavformat/swfenc.c
@@ -348,7 +348,7 @@ static int swf_write_video(AVFormatContext *s,
avio_wl16(pb, enc->width);
avio_wl16(pb, enc->height);
avio_w8(pb, 0);
- avio_w8(pb,ff_codec_get_tag(swf_codec_tags,enc->codec_id));
+ avio_w8(pb,ff_codec_get_tag(ff_swf_codec_tags, enc->codec_id));
put_swf_end_tag(s);
/* place the video object for the first time */