[xiph-commits] r16410 - in branches/theora-thusnelda: include/theora lib/dec/x86_vc lib/enc

tterribe at svn.xiph.org tterribe at svn.xiph.org
Mon Aug 3 23:23:05 PDT 2009


Author: tterribe
Date: 2009-08-03 23:23:05 -0700 (Mon, 03 Aug 2009)
New Revision: 16410

Modified:
   branches/theora-thusnelda/include/theora/theoraenc.h
   branches/theora-thusnelda/lib/dec/x86_vc/mmxloop.h
   branches/theora-thusnelda/lib/enc/encode.c
Log:
Add encoder controls to change the quality and bitrate targets during the
 middle of an encode.


Modified: branches/theora-thusnelda/include/theora/theoraenc.h
===================================================================
--- branches/theora-thusnelda/include/theora/theoraenc.h	2009-08-04 06:19:12 UTC (rev 16409)
+++ branches/theora-thusnelda/include/theora/theoraenc.h	2009-08-04 06:23:05 UTC (rev 16410)
@@ -243,8 +243,9 @@
 #define TH_ENCCTL_2PASS_OUT (24)
 /**Submits two-pass encoding metric data collected the first encoding pass to
  *  the second pass.
- * The first call must be made before the first frame is encoded, and sets the
- *  encoder to pass 2 mode implicitly.
+ * The first call must be made before the first frame is encoded, and a target
+ *  bitrate must have already been specified to the encoder.
+ * It sets the encoder to pass 2 mode implicitly; this cannot be disabled.
  * The encoder may require reading data from some or all of the frames in
  *  advance, depending on, e.g., the reservoir size used in the second pass.
  * You must call this function repeatedly before each frame to provide data
@@ -275,8 +276,9 @@
  * \retval >0            The number of bytes of metric data required/consumed.
  * \retval 0             No more data is required before the next frame.
  * \retval TH_EFAULT     \a _enc_ctx is <tt>NULL</tt>.
- * \retval TH_EINVAL     The first call was made after the first frame was
- *                        submitted for encoding.
+ * \retval TH_EINVAL     No target bitrate has been set, or the first call was
+ *                        made after the first frame was submitted for
+ *                        encoding.
  * \retval TH_ENOTFORMAT The data did not appear to be pass 1 from a compatible
  *                        implementation of this library.
  * \retval TH_EBADHEADER The data was invalid; this may be returned when
@@ -285,6 +287,44 @@
  *                        data.
  * \retval TH_IMPL       Not supported by this implementation.*/
 #define TH_ENCCTL_2PASS_IN (26)
+/**Sets the current encoding quality.
+ * This is only valid so long as no bitrate has been specified, either through
+ *  the #th_info struct used to initialize the encoder or through
+ *  #TH_ENCCTL_SET_BITRATE (this restriction may be relaxed in a future
+ *  version).
+ * If it is set before the headers are emitted, the target quality encoded in
+ *  them will be updated.
+ *
+ * \param[in] _buf <tt>int</tt>: The new target quality, in the range 0...63,
+ *                  inclusive.
+ * \retval 0             Success.
+ * \retval TH_EFAULT     \a _enc_ctx or \a _buf is <tt>NULL</tt>.
+ * \retval TH_EINVAL     A target bitrate has already been specified, or the
+ *                        quality index was not in the range 0...63.
+ * \retval TH_IMPL       Not supported by this implementation.*/
+#define TH_ENCCTL_SET_QUALITY (28)
+/**Sets the current encoding bitrate.
+ * Once a bitrate is set, the encoder must use a rate-controlled mode for all
+ *  future frames (this restriction may be relaxed in a future version).
+ * If it is set before the headers are emitted, the target bitrate encoded in
+ *  them will be updated.
+ * Due to the buffer delay, the exact bitrate of each section of the encode is
+ *  not guaranteed.
+ * The encoder may have already used more bits than allowed for the frames it
+ *  has encoded, expecting to make them up in future frames, or it may have
+ *  used fewer, holding the excess in reserve.
+ * The exact transition between the two bitrates is not well-defined by this
+ *  API, but may be affected by flags set with #TH_ENCCTL_SET_RATE_FLAGS.
+ * After a number of frames equal to the buffer delay, one may expect further
+ *  output to average at the target bitrate.
+ *
+ * \param[in] _buf <tt>long</tt>: The new target bitrate, in bits per second.
+ * \retval 0             Success.
+ * \retval TH_EFAULT     \a _enc_ctx or \a _buf is <tt>NULL</tt>.
+ * \retval TH_EINVAL     The target bitrate was not positive.
+ * \retval TH_IMPL       Not supported by this implementation.*/
+#define TH_ENCCTL_SET_BITRATE (30)
+
 /*@}*/
 
 

Modified: branches/theora-thusnelda/lib/dec/x86_vc/mmxloop.h
===================================================================
--- branches/theora-thusnelda/lib/dec/x86_vc/mmxloop.h	2009-08-04 06:19:12 UTC (rev 16409)
+++ branches/theora-thusnelda/lib/dec/x86_vc/mmxloop.h	2009-08-04 06:23:05 UTC (rev 16410)
@@ -93,7 +93,7 @@
 #define OC_LOOP_FILTER_V_MMX(_pix,_ystride,_ll) \
   do{ \
     /*Used local variable pix__ in order to fix compilation errors like: \
-     "error C2425: 'SHL' : non-constant expression in 'second operand'".*/ \
+       "error C2425: 'SHL' : non-constant expression in 'second operand'".*/ \
     unsigned char *pix__; \
     unsigned char *ll__; \
     ll__=(_ll); \
@@ -123,7 +123,7 @@
 #define OC_LOOP_FILTER_H_MMX(_pix,_ystride,_ll) \
   do{ \
     /*Used local variable ll__ in order to fix compilation errors like: \
-     "error C2443: operand size conflict".*/ \
+       "error C2443: operand size conflict".*/ \
     unsigned char *ll__; \
     unsigned char *pix__; \
     ll__=(_ll); \

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2009-08-04 06:19:12 UTC (rev 16409)
+++ branches/theora-thusnelda/lib/enc/encode.c	2009-08-04 06:23:05 UTC (rev 16410)
@@ -1330,6 +1330,29 @@
       _enc->dup_count=OC_MAXI(dup_count,0);
       return 0;
     }break;
+    case TH_ENCCTL_SET_QUALITY:{
+      int qi;
+      if(_enc==NULL||_buf==NULL)return TH_EFAULT;
+      if(_enc->state.info.target_bitrate>0)return TH_EINVAL;
+      qi=*(int *)_buf;
+      if(qi<0||qi>63)return TH_EINVAL;
+      _enc->state.info.quality=qi;
+      _enc->state.qis[0]=(unsigned char)qi;
+      _enc->state.nqis=1;
+      return 0;
+    }break;
+    case TH_ENCCTL_SET_BITRATE:{
+      long bitrate;
+      int  reset;
+      if(_enc==NULL||_buf==NULL)return TH_EFAULT;
+      bitrate=*(long *)bitrate;
+      if(bitrate<=0)return TH_EINVAL;
+      reset=_enc->state.info.target_bitrate<=0;
+      _enc->state.info.target_bitrate=bitrate>INT_MAX?INT_MAX:bitrate;
+      if(reset)oc_rc_state_init(&_enc->rc,_enc);
+      else oc_enc_rc_resize(_enc);
+      return 0;
+    }break;
     case TH_ENCCTL_SET_RATE_FLAGS:{
       int set;
       if(_enc==NULL||_buf==NULL)return TH_EFAULT;



More information about the commits mailing list