Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support mms stream selection

  • Loading branch information...
commit cf65d9a2fbc10d0d742bdc5a86fd3c0d5ba74ef9 1 parent b7329a3
@qrtt1 qrtt1 authored
View
2  libavformat/Makefile
@@ -353,6 +353,8 @@ OBJS-$(CONFIG_HTTPPROXY_PROTOCOL) += http.o httpauth.o
OBJS-$(CONFIG_HTTPS_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) += mms_plus.o
+OBJS-$(CONFIG_MMST_PROTOCOL) += mms_plus.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
@@ -30,6 +30,7 @@
#include "libavutil/avstring.h"
#include "libavutil/opt.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_internal(URLContext *h, const char *uri, int flags, int tim
char headers[1024];
MMSHContext *mmsh = h->priv_data;
MMSContext *mms;
+ int select_index_enable;
mmsh->request_seq = h->is_streamed = 1;
mms = &mmsh->mms;
@@ -266,13 +268,38 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
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_internal(URLContext *h, const char *uri, int flags, int tim
"Pragma: stream-switch-entry=%s\r\n"
"Pragma: no-cache,rate=1.000000,stream-time=%u"
"Connection: Close\r\n",
- host, port, mmsh->request_seq++, mms->stream_num, stream_selection, timestamp);
+ 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);
av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
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 cf65d9a

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