[xiph-cvs] cvs commit: win32-tools/oggdrop encode.c

Chris Wolf cwolf at xiph.org
Sat Jan 5 10:52:35 PST 2002



cwolf       02/01/05 10:52:35

  Modified:    oggdrop  encode.c
  Log:
  patches per john.edwards33 at ntlworld.com to incorporate bitrate option.

Revision  Changes    Path
1.5       +48 -28    win32-tools/oggdrop/encode.c

Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/encode.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- encode.c	2002/01/03 09:12:13	1.4
+++ encode.c	2002/01/05 18:52:34	1.5
@@ -19,6 +19,7 @@
 
 #define READSIZE 1024
 
+extern int nominalBitrate;
 
 int oe_write_page(ogg_page *page, FILE *fp);
 
@@ -48,14 +49,28 @@
         /* Have vorbisenc choose a mode for us */
         vorbis_info_init(&vi);
   
-  /* Not yet...
-  if (opt->oeMode == OE_MODE_BITRATE)
-	  vorbis_encode_init(&vi, opt->channels, opt->rate, -1, 
-			opt->bitrate*1000, -1);
-  else
-  */
-    vorbis_encode_init_vbr(&vi, opt->channels, opt->rate, 
-                                opt->quality_coefficient);
+	if (opt->oeMode == OE_MODE_BITRATE)
+  {
+		if (vorbis_encode_init(&vi, opt->channels, opt->rate, -1, 
+			opt->bitrate*1000, -1))
+    {
+      opt->error("Can't encode with selected params/file attrs");
+      vorbis_info_clear(&vi);
+      return 1;
+    }
+  }
+	else
+  {
+	  if (vorbis_encode_init_vbr(&vi, opt->channels, opt->rate, 
+                        opt->quality_coefficient))
+    {
+      opt->error("Can't encode with selected params/file attrs");
+      vorbis_info_clear(&vi);
+      return 1;
+    }
+    else
+      nominalBitrate = vi.bitrate_nominal;
+  }
 
         /* Now, set up the analysis engine, stream encoder, and other
            preparation before the encoding begins.
@@ -138,32 +153,37 @@
                 {
 
                         /* Do the main analysis, creating a packet */
-			vorbis_analysis(&vb, &op);
+      vorbis_analysis(&vb,NULL);	
+			vorbis_bitrate_addblock(&vb);
 
-			/* Add packet to bitstream */
-			ogg_stream_packetin(&os,&op);
-			packetsdone++;
+			while(vorbis_bitrate_flushpacket(&vd, &op)) 
+			{
 
-			/* If we've gone over a page boundary, we can do actual output,
-			   so do so (for however many pages are available) */
+				/* Add packet to bitstream */
+				ogg_stream_packetin(&os,&op);
+				packetsdone++;
 
-			while(!eos)
-			{
-				int result = ogg_stream_pageout(&os,&og);
-				if(!result) break;
+				/* If we've gone over a page boundary, we can do actual output,
+				   so do so (for however many pages are available) */
 
-				ret = oe_write_page(&og, opt->out);
-				if(!ret)
+				while(!eos)
                                 {
-					opt->error("Failed writing data to output stream\n");
-					ret = 1;
-					goto cleanup; /* Bail */
-				}
-				else
-					bytes_written += ret; 
+					int result = ogg_stream_pageout(&os,&og);
+					if(!result) break;
 
-				if(ogg_page_eos(&og))
-					eos = 1;
+					ret = oe_write_page(&og, opt->out);
+					if(!ret)
+					{
+						opt->error("Failed writing data to output stream\n");
+						ret = 1;
+						goto cleanup; /* Bail */
+					}
+					else
+						bytes_written += ret; 
+
+					if(ogg_page_eos(&og))
+						eos = 1;
+				}
                         }
                 }
         }

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list