shithub: opusfile

Download patch

ref: 9df7ae98d0de6d368248ce7dab60a12b48ba445e
parent: 8d04070b0c74480ac312f48fe18f076cb11e01c2
author: Timothy B. Terriberry <tterribe@xiph.org>
date: Sat Sep 22 06:16:14 EDT 2012

Add URL support to seeking_example.

Also fixes some indenting in opusfile_example.

--- a/examples/opusfile_example.c
+++ b/examples/opusfile_example.c
@@ -43,14 +43,14 @@
     of=op_open_url(_argv[1],OP_SSL_SKIP_CERTIFICATE_CHECK,&ret);
 #if 0
     if(of==NULL){
-        OpusFileCallbacks  cb={NULL,NULL,NULL,NULL};
-        void              *fp;
-        /*For debugging: force a file to not be seekable.*/
-        fp=op_fopen(&cb,_argv[1],"rb");
-        cb.seek=NULL;
-        cb.tell=NULL;
-        of=op_open_callbacks(fp,&cb,NULL,0,NULL);
-      }
+      OpusFileCallbacks  cb={NULL,NULL,NULL,NULL};
+      void              *fp;
+      /*For debugging: force a file to not be seekable.*/
+      fp=op_fopen(&cb,_argv[1],"rb");
+      cb.seek=NULL;
+      cb.tell=NULL;
+      of=op_open_callbacks(fp,&cb,NULL,0,NULL);
+    }
 #else
     if(of==NULL)of=op_open_file(_argv[1],&ret);
 #endif
--- a/examples/seeking_example.c
+++ b/examples/seeking_example.c
@@ -248,7 +248,12 @@
   }
   memset(&cb,0,sizeof(cb));
   if(strcmp(_argv[1],"-")==0)fp=op_fdopen(&cb,fileno(stdin),"rb");
-  else fp=op_fopen(&cb,_argv[1],"rb");
+  else{
+    /*Try to treat the argument as a URL.*/
+    fp=op_url_stream_create(&cb,_argv[1],OP_SSL_SKIP_CERTIFICATE_CHECK);
+    /*Fall back assuming it's a regular file name.*/
+    if(fp==NULL)fp=op_fopen(&cb,_argv[1],"rb");
+  }
   if(cb.seek!=NULL){
     real_seek=cb.seek;
     cb.seek=seek_stat_counter;