Skip to content
Browse files

support mms stream selection

Conflicts:

	libavformat/Makefile
  • Loading branch information...
1 parent ac90151 commit 9d0dc4b83a1752b66774fc66ad2cc0e348d732bb @qrtt1 qrtt1 committed
Showing with 108 additions and 7 deletions.
  1. +2 −2 libavformat/Makefile
  2. +42 −0 libavformat/mms_plus.c
  3. +11 −0 libavformat/mms_plus.h
  4. +31 −3 libavformat/mmsh.c
  5. +22 −2 libavformat/mmst.c
View
4 libavformat/Makefile
@@ -323,8 +323,8 @@ OBJS-$(CONFIG_CRYPTO_PROTOCOL) += crypto.o
OBJS-$(CONFIG_FILE_PROTOCOL) += file.o
OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o
OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o
-OBJS-$(CONFIG_MMSH_PROTOCOL) += mmsh.o mms.o asf.o
-OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o
+OBJS-$(CONFIG_MMSH_PROTOCOL) += mmsh.o mms.o asf.o mms_plus.o
+OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o mms_plus.o
OBJS-$(CONFIG_SHOUTCAST_PROTOCOL) += shoutcast.o
OBJS-$(CONFIG_MD5_PROTOCOL) += md5proto.o
OBJS-$(CONFIG_PIPE_PROTOCOL) += file.o
View
42 libavformat/mms_plus.c
@@ -0,0 +1,42 @@
+#include "mms_plus.h"
+#include <stdio.h>
+
+
+static int mms_plus_default_video_index_cb(void)
+{
+ return -1;
+}
+
+static int mms_plus_default_audio_index_cb(void)
+{
+ return -1;
+}
+
+static int (*mms_plus_video_index_cb)(void) = mms_plus_default_video_index_cb;
+static int (*mms_plus_audio_index_cb)(void) = mms_plus_default_audio_index_cb;
+
+int mms_plus_video_index(void)
+{
+ return mms_plus_video_index_cb();
+}
+
+int mms_plus_audio_index(void)
+{
+ return mms_plus_audio_index_cb();
+}
+
+void mms_plus_set_video_index_cb(int (*cb)(void))
+{
+ if(cb != NULL)
+ mms_plus_video_index_cb = cb;
+ else
+ mms_plus_video_index_cb = mms_plus_default_video_index_cb;
+}
+
+void mms_plus_set_audio_index_cb(int (*cb)(void))
+{
+ if(cb != NULL)
+ mms_plus_audio_index_cb = cb;
+ else
+ mms_plus_audio_index_cb = mms_plus_default_audio_index_cb;
+}
View
11 libavformat/mms_plus.h
@@ -0,0 +1,11 @@
+#ifndef AVFORMAT_MMS_PLUS_H
+#define AVFORMAT_MMS_PLUS_H
+
+int mms_plus_video_index(void);
+int mms_plus_audio_index(void);
+
+void mms_plus_set_video_index_cb(int (*cb)(void));
+void mms_plus_set_audio_index_cb(int (*cb)(void));
+
+#endif
+
View
34 libavformat/mmsh.c
@@ -29,6 +29,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
#include "internal.h"
+#include "mms_plus.h"
#include "mms.h"
#include "asf.h"
#include "http.h"
@@ -219,6 +220,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
char headers[1024];
MMSHContext *mmsh;
MMSContext *mms;
+ int select_index_enable;
mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext));
if (!h->priv_data)
@@ -267,13 +269,38 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
stream_selection = av_mallocz(mms->stream_num * 19 + 1);
if (!stream_selection)
return AVERROR(ENOMEM);
- for (i = 0; i < mms->stream_num; i++) {
+
+ av_log(NULL, AV_LOG_WARNING,"select video index: %d\n", mms_plus_video_index());
+ av_log(NULL, AV_LOG_WARNING,"select audio index: %d\n", mms_plus_audio_index());
+
+ select_index_enable = mms_plus_video_index() >=0 && mms_plus_audio_index() >= 0;
+ av_log(NULL, AV_LOG_INFO,"enable stream selection: %d\n", select_index_enable);
+
+ if(select_index_enable) {
char tmp[20];
- err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[i].id);
+
+ /* select video index */
+ err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[mms_plus_video_index()].id);
+ if (err < 0)
+ goto fail;
+ av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1);
+
+ /* select audio index */
+ err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[mms_plus_audio_index()].id);
if (err < 0)
goto fail;
av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1);
}
+ else {
+ for (i = 0; i < mms->stream_num; i++) {
+ char tmp[20];
+ err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[i].id);
+ if (err < 0)
+ goto fail;
+ av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1);
+ }
+ }
+
// send play request
err = snprintf(headers, sizeof(headers),
"Accept: */*\r\n"
@@ -285,12 +312,13 @@ static int mmsh_open(URLContext *h, const char *uri, int flags)
"Pragma: stream-switch-count=%d\r\n"
"Pragma: stream-switch-entry=%s\r\n"
"Connection: Close\r\n",
- host, port, mmsh->request_seq++, mms->stream_num, stream_selection);
+ host, port, mmsh->request_seq++, select_index_enable ? 2 : mms->stream_num, stream_selection);
av_freep(&stream_selection);
if (err < 0) {
av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n");
goto fail;
}
+
av_dlog(NULL, "out_buffer is %s", headers);
ff_http_set_headers(mms->mms_hd, headers);
View
24 libavformat/mmst.c
@@ -29,6 +29,7 @@
*/
#include "avformat.h"
+#include "mms_plus.h"
#include "mms.h"
#include "internal.h"
#include "avio_internal.h"
@@ -437,15 +438,34 @@ static int send_startup_packet(MMSTContext *mmst)
static int send_stream_selection_request(MMSTContext *mmst)
{
int i;
+ int select_index_enable;
+
+ av_log(NULL, AV_LOG_WARNING,"select video index: %d\n", mms_plus_video_index());
+ av_log(NULL, AV_LOG_WARNING,"select audio index: %d\n", mms_plus_audio_index());
+
+ select_index_enable = mms_plus_video_index() >=0 && mms_plus_audio_index() >= 0;
+ av_log(NULL, AV_LOG_INFO,"enable stream selection: %d\n", select_index_enable);
MMSContext *mms = &mmst->mms;
// send the streams we want back...
start_command_packet(mmst, CS_PKT_STREAM_ID_REQUEST);
bytestream_put_le32(&mms->write_out_ptr, mms->stream_num); // stream nums
- for(i= 0; i<mms->stream_num; i++) {
+
+ if(select_index_enable) {
+ bytestream_put_le16(&mms->write_out_ptr, 0xffff); // flags
+ bytestream_put_le16(&mms->write_out_ptr, mms->streams[mms_plus_video_index()].id); // stream id
+ bytestream_put_le16(&mms->write_out_ptr, 0); // selection
+
bytestream_put_le16(&mms->write_out_ptr, 0xffff); // flags
- bytestream_put_le16(&mms->write_out_ptr, mms->streams[i].id); // stream id
+ bytestream_put_le16(&mms->write_out_ptr, mms->streams[mms_plus_audio_index()].id); // stream id
bytestream_put_le16(&mms->write_out_ptr, 0); // selection
}
+ else {
+ for(i= 0; i<mms->stream_num; i++) {
+ bytestream_put_le16(&mms->write_out_ptr, 0xffff); // flags
+ bytestream_put_le16(&mms->write_out_ptr, mms->streams[i].id); // stream id
+ bytestream_put_le16(&mms->write_out_ptr, 0); // selection
+ }
+ }
return send_command_packet(mmst);
}

0 comments on commit 9d0dc4b

Please sign in to comment.
Something went wrong with that request. Please try again.