From 34060b0c0cb13eed323577becf72a13b43654c00 Mon Sep 17 00:00:00 2001 From: Amit Date: Thu, 19 Nov 2015 13:35:30 +0100 Subject: [PATCH 2/8] Add a new testfiledownload.c example New test code which connects to a mms url and downloads this as a file to the local machine using mmsx_connect and mmsx_get_length(). --- src/Makefile.am | 4 +- src/testdownload.c | 29 ---------- src/testfiledownload.c | 114 +++++++++++++++++++++++++++++++++++++++ src/teststreamdownload.c | 29 ++++++++++ 4 files changed, 145 insertions(+), 31 deletions(-) delete mode 100644 src/testdownload.c create mode 100644 src/testfiledownload.c create mode 100644 src/teststreamdownload.c diff --git a/src/Makefile.am b/src/Makefile.am index 4fbb5c0..295cc34 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -# noinst_PROGRAMS = testconnect testdownload testswap +# noinst_PROGRAMS = testconnect testfiledownload teststreamdownload testswap lib_LTLIBRARIES = libmms.la @@ -46,5 +46,5 @@ INCLUDES = \ DEPS = $(top_builddir)/src/libmms.la LDADD = $(top_builddir)/src/libmms.la -# libmms_test_SOURCES = testconnect.c testdownload.c testswap.c +# libmms_test_SOURCES = testconnect.c testfiledownload.c teststreamdownload.c testswap.c # libmms_test_LDADD = $(LDADD) diff --git a/src/testfiledownload.c b/src/testfiledownload.c new file mode 100644 index 0000000..cfef631 --- /dev/null +++ b/src/testfiledownload.c @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2002-2004 the xine project + * Copyright (C) 2004-2012 the libmms project + * + * This file is part of LibMMS, an MMS protocol handling library. + * This file was originally a part of xine, a free video player. + * + * Libmms is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Libmms 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 General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA + * This file is created by : Amit Kumar (amit3.kumar@samsung.com) +*/ + +/* Sample program: Connect a mms URL and download media file on local machine. */ + + + + + +#include + +#include "mms.h" +#include "mmsx.h" + +#define ERROR 1 + +// Working MMS URL + +const char *url = "mms://a1014.v1252931.c125293.g.vm.akamaistream.net/7/1014/125293/v0001/wm.od.origin.zdf.de.gl-systemhaus.de/none/zdf/09/09/090925_hinweis_geo_de_vh.wmv"; + +int main() +{ + mmsx_t * pMMSX = NULL; + FILE* localFileHandle; + int loop, readMediaResult; + const char *localMediaName = "/tmp/mmsdownload.wmv"; + char buf[1024]; + + //Here we make a connection to the passed URL. + + if(pMMSX = mmsx_connect(NULL, NULL, url, 1024)) + { + printf("Connect OK\n"); + } + else + { + printf("Not connected\n"); + + return ERROR; + } + + //Open file handler for local media file. + + localFileHandle = fopen(localMediaName, "w"); + + if(!localFileHandle) + { + printf("Cannot open file to write\n"); + return ERROR; + } + /* + ** + * mmsx_get_time_length() function will calculate the time + * duration of media file. + ** + */ + + printf("Time duration of media file = %lf\n",mmsx_get_time_length(pMMSX)); + + /* + ** + * This loop will iterate total media length i.e. media size + * divided by buffer size. In our case buffer size is 1024. + ** + */ + + for(loop = 0; loop < mmsx_get_length(pMMSX)/1024; loop++) + { + readMediaResult = mmsx_read (NULL, pMMSX, buf,1024); + if(!readMediaResult) + break; + + //Finally, writing local media file. + + fwrite(buf, 1, readMediaResult, localFileHandle); + } + + // For print only + + if(loop > 0) + { + printf("Reading file successfully and reading the file %d times\n", loop); + } + else + { + printf("Failed to read from stream\n"); + } + + //closed opend handler here. + + fclose(localFileHandle); + mmsx_close(pMMSX); +} diff --git a/src/teststreamdownload.c b/src/teststreamdownload.c new file mode 100644 index 0000000..21d2d56 --- /dev/null +++ b/src/teststreamdownload.c @@ -0,0 +1,29 @@ +#include +#include "mms.h" + +const char *url = "mms://od-msn.msn.com/3/mbr/apprentice_bts.wmv"; + +int main(int argc, char *argv[]) +{ + mms_t *this = NULL; + char buf[1024]; + int i, res; + FILE* f; + + if((this = mms_connect(NULL, NULL, url, 1))) + printf("Connect OK\n"); + f = fopen("/tmp/mmsdownload.test", "w"); + for(i = 0; i < 10000; i++) + { + res = mms_read(NULL, this, buf, 1024); + if(!res) + break; + fwrite(buf, 1, res, f); + } + if(i > 0) + printf("OK, read %d times\n", i); + else + printf("Failed to read from stream\n"); + + +} -- 2.39.2