Skip to content

Commit

Permalink
support mms stream selection
Browse files Browse the repository at this point in the history
  • Loading branch information
qrtt1 committed Mar 14, 2012
1 parent b7329a3 commit cf65d9a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 5 deletions.
2 changes: 2 additions & 0 deletions libavformat/Makefile
Expand Up @@ -353,6 +353,8 @@ OBJS-$(CONFIG_HTTPPROXY_PROTOCOL) += http.o httpauth.o
OBJS-$(CONFIG_HTTPS_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_MMSH_PROTOCOL) += mmsh.o mms.o asf.o
OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.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_MD5_PROTOCOL) += md5proto.o
OBJS-$(CONFIG_PIPE_PROTOCOL) += file.o OBJS-$(CONFIG_PIPE_PROTOCOL) += file.o


Expand Down
42 changes: 42 additions & 0 deletions 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;
}
11 changes: 11 additions & 0 deletions 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

34 changes: 31 additions & 3 deletions libavformat/mmsh.c
Expand Up @@ -30,6 +30,7 @@
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "internal.h" #include "internal.h"
#include "mms_plus.h"
#include "mms.h" #include "mms.h"
#include "asf.h" #include "asf.h"
#include "http.h" #include "http.h"
Expand Down Expand Up @@ -219,6 +220,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
char headers[1024]; char headers[1024];
MMSHContext *mmsh = h->priv_data; MMSHContext *mmsh = h->priv_data;
MMSContext *mms; MMSContext *mms;
int select_index_enable;


mmsh->request_seq = h->is_streamed = 1; mmsh->request_seq = h->is_streamed = 1;
mms = &mmsh->mms; mms = &mmsh->mms;
Expand Down Expand Up @@ -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); stream_selection = av_mallocz(mms->stream_num * 19 + 1);
if (!stream_selection) if (!stream_selection)
return AVERROR(ENOMEM); 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]; 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) if (err < 0)
goto fail; goto fail;
av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1); 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 // send play request
err = snprintf(headers, sizeof(headers), err = snprintf(headers, sizeof(headers),
"Accept: */*\r\n" "Accept: */*\r\n"
Expand All @@ -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: stream-switch-entry=%s\r\n"
"Pragma: no-cache,rate=1.000000,stream-time=%u" "Pragma: no-cache,rate=1.000000,stream-time=%u"
"Connection: Close\r\n", "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); av_freep(&stream_selection);
if (err < 0) { if (err < 0) {
av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n"); av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n");
goto fail; goto fail;
} }

av_dlog(NULL, "out_buffer is %s", headers); av_dlog(NULL, "out_buffer is %s", headers);
av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0); av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);


Expand Down
24 changes: 22 additions & 2 deletions libavformat/mmst.c
Expand Up @@ -29,6 +29,7 @@
*/ */


#include "avformat.h" #include "avformat.h"
#include "mms_plus.h"
#include "mms.h" #include "mms.h"
#include "internal.h" #include "internal.h"
#include "avio_internal.h" #include "avio_internal.h"
Expand Down Expand Up @@ -437,15 +438,34 @@ static int send_startup_packet(MMSTContext *mmst)
static int send_stream_selection_request(MMSTContext *mmst) static int send_stream_selection_request(MMSTContext *mmst)
{ {
int i; 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; MMSContext *mms = &mmst->mms;
// send the streams we want back... // send the streams we want back...
start_command_packet(mmst, CS_PKT_STREAM_ID_REQUEST); start_command_packet(mmst, CS_PKT_STREAM_ID_REQUEST);
bytestream_put_le32(&mms->write_out_ptr, mms->stream_num); // stream nums 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, 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 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); return send_command_packet(mmst);
} }


Expand Down

0 comments on commit cf65d9a

Please sign in to comment.