Skip to content
This repository
Browse code

support mms stream selection

  • Loading branch information...
commit cf65d9a2fbc10d0d742bdc5a86fd3c0d5ba74ef9 1 parent b7329a3
Ching Yi, Chan qrtt1 authored
2  libavformat/Makefile
@@ -353,6 +353,8 @@ OBJS-$(CONFIG_HTTPPROXY_PROTOCOL) += http.o httpauth.o
353 353 OBJS-$(CONFIG_HTTPS_PROTOCOL) += http.o httpauth.o
354 354 OBJS-$(CONFIG_MMSH_PROTOCOL) += mmsh.o mms.o asf.o
355 355 OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o
  356 +OBJS-$(CONFIG_MMSH_PROTOCOL) += mms_plus.o
  357 +OBJS-$(CONFIG_MMST_PROTOCOL) += mms_plus.o
356 358 OBJS-$(CONFIG_MD5_PROTOCOL) += md5proto.o
357 359 OBJS-$(CONFIG_PIPE_PROTOCOL) += file.o
358 360
42 libavformat/mms_plus.c
... ... @@ -0,0 +1,42 @@
  1 +#include "mms_plus.h"
  2 +#include <stdio.h>
  3 +
  4 +
  5 +static int mms_plus_default_video_index_cb(void)
  6 +{
  7 + return -1;
  8 +}
  9 +
  10 +static int mms_plus_default_audio_index_cb(void)
  11 +{
  12 + return -1;
  13 +}
  14 +
  15 +static int (*mms_plus_video_index_cb)(void) = mms_plus_default_video_index_cb;
  16 +static int (*mms_plus_audio_index_cb)(void) = mms_plus_default_audio_index_cb;
  17 +
  18 +int mms_plus_video_index(void)
  19 +{
  20 + return mms_plus_video_index_cb();
  21 +}
  22 +
  23 +int mms_plus_audio_index(void)
  24 +{
  25 + return mms_plus_audio_index_cb();
  26 +}
  27 +
  28 +void mms_plus_set_video_index_cb(int (*cb)(void))
  29 +{
  30 + if(cb != NULL)
  31 + mms_plus_video_index_cb = cb;
  32 + else
  33 + mms_plus_video_index_cb = mms_plus_default_video_index_cb;
  34 +}
  35 +
  36 +void mms_plus_set_audio_index_cb(int (*cb)(void))
  37 +{
  38 + if(cb != NULL)
  39 + mms_plus_audio_index_cb = cb;
  40 + else
  41 + mms_plus_audio_index_cb = mms_plus_default_audio_index_cb;
  42 +}
11 libavformat/mms_plus.h
... ... @@ -0,0 +1,11 @@
  1 +#ifndef AVFORMAT_MMS_PLUS_H
  2 +#define AVFORMAT_MMS_PLUS_H
  3 +
  4 +int mms_plus_video_index(void);
  5 +int mms_plus_audio_index(void);
  6 +
  7 +void mms_plus_set_video_index_cb(int (*cb)(void));
  8 +void mms_plus_set_audio_index_cb(int (*cb)(void));
  9 +
  10 +#endif
  11 +
34 libavformat/mmsh.c
@@ -30,6 +30,7 @@
30 30 #include "libavutil/avstring.h"
31 31 #include "libavutil/opt.h"
32 32 #include "internal.h"
  33 +#include "mms_plus.h"
33 34 #include "mms.h"
34 35 #include "asf.h"
35 36 #include "http.h"
@@ -219,6 +220,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
219 220 char headers[1024];
220 221 MMSHContext *mmsh = h->priv_data;
221 222 MMSContext *mms;
  223 + int select_index_enable;
222 224
223 225 mmsh->request_seq = h->is_streamed = 1;
224 226 mms = &mmsh->mms;
@@ -266,13 +268,38 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
266 268 stream_selection = av_mallocz(mms->stream_num * 19 + 1);
267 269 if (!stream_selection)
268 270 return AVERROR(ENOMEM);
269   - for (i = 0; i < mms->stream_num; i++) {
  271 +
  272 + av_log(NULL, AV_LOG_WARNING,"select video index: %d\n", mms_plus_video_index());
  273 + av_log(NULL, AV_LOG_WARNING,"select audio index: %d\n", mms_plus_audio_index());
  274 +
  275 + select_index_enable = mms_plus_video_index() >=0 && mms_plus_audio_index() >= 0;
  276 + av_log(NULL, AV_LOG_INFO,"enable stream selection: %d\n", select_index_enable);
  277 +
  278 + if(select_index_enable) {
270 279 char tmp[20];
271   - err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[i].id);
  280 +
  281 + /* select video index */
  282 + err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[mms_plus_video_index()].id);
  283 + if (err < 0)
  284 + goto fail;
  285 + av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1);
  286 +
  287 + /* select audio index */
  288 + err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[mms_plus_audio_index()].id);
272 289 if (err < 0)
273 290 goto fail;
274 291 av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1);
275 292 }
  293 + else {
  294 + for (i = 0; i < mms->stream_num; i++) {
  295 + char tmp[20];
  296 + err = snprintf(tmp, sizeof(tmp), "ffff:%d:0 ", mms->streams[i].id);
  297 + if (err < 0)
  298 + goto fail;
  299 + av_strlcat(stream_selection, tmp, mms->stream_num * 19 + 1);
  300 + }
  301 + }
  302 +
276 303 // send play request
277 304 err = snprintf(headers, sizeof(headers),
278 305 "Accept: */*\r\n"
@@ -285,12 +312,13 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
285 312 "Pragma: stream-switch-entry=%s\r\n"
286 313 "Pragma: no-cache,rate=1.000000,stream-time=%u"
287 314 "Connection: Close\r\n",
288   - host, port, mmsh->request_seq++, mms->stream_num, stream_selection, timestamp);
  315 + host, port, mmsh->request_seq++, select_index_enable ? 2 : mms->stream_num, stream_selection);
289 316 av_freep(&stream_selection);
290 317 if (err < 0) {
291 318 av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n");
292 319 goto fail;
293 320 }
  321 +
294 322 av_dlog(NULL, "out_buffer is %s", headers);
295 323 av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
296 324
24 libavformat/mmst.c
@@ -29,6 +29,7 @@
29 29 */
30 30
31 31 #include "avformat.h"
  32 +#include "mms_plus.h"
32 33 #include "mms.h"
33 34 #include "internal.h"
34 35 #include "avio_internal.h"
@@ -437,15 +438,34 @@ static int send_startup_packet(MMSTContext *mmst)
437 438 static int send_stream_selection_request(MMSTContext *mmst)
438 439 {
439 440 int i;
  441 + int select_index_enable;
  442 +
  443 + av_log(NULL, AV_LOG_WARNING,"select video index: %d\n", mms_plus_video_index());
  444 + av_log(NULL, AV_LOG_WARNING,"select audio index: %d\n", mms_plus_audio_index());
  445 +
  446 + select_index_enable = mms_plus_video_index() >=0 && mms_plus_audio_index() >= 0;
  447 + av_log(NULL, AV_LOG_INFO,"enable stream selection: %d\n", select_index_enable);
440 448 MMSContext *mms = &mmst->mms;
441 449 // send the streams we want back...
442 450 start_command_packet(mmst, CS_PKT_STREAM_ID_REQUEST);
443 451 bytestream_put_le32(&mms->write_out_ptr, mms->stream_num); // stream nums
444   - for(i= 0; i<mms->stream_num; i++) {
  452 +
  453 + if(select_index_enable) {
  454 + bytestream_put_le16(&mms->write_out_ptr, 0xffff); // flags
  455 + bytestream_put_le16(&mms->write_out_ptr, mms->streams[mms_plus_video_index()].id); // stream id
  456 + bytestream_put_le16(&mms->write_out_ptr, 0); // selection
  457 +
445 458 bytestream_put_le16(&mms->write_out_ptr, 0xffff); // flags
446   - bytestream_put_le16(&mms->write_out_ptr, mms->streams[i].id); // stream id
  459 + bytestream_put_le16(&mms->write_out_ptr, mms->streams[mms_plus_audio_index()].id); // stream id
447 460 bytestream_put_le16(&mms->write_out_ptr, 0); // selection
448 461 }
  462 + else {
  463 + for(i= 0; i<mms->stream_num; i++) {
  464 + bytestream_put_le16(&mms->write_out_ptr, 0xffff); // flags
  465 + bytestream_put_le16(&mms->write_out_ptr, mms->streams[i].id); // stream id
  466 + bytestream_put_le16(&mms->write_out_ptr, 0); // selection
  467 + }
  468 + }
449 469 return send_command_packet(mmst);
450 470 }
451 471

0 comments on commit cf65d9a

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