]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libxvid_rc.c
cook: use AVCodecContext.channels instead of keeping a private copy
[ffmpeg] / libavcodec / libxvid_rc.c
index e87142749e2f590be236f0072376bb3dc59ef89d..bf9f6f07384480291d82254a058cdb43dadf0c11 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include <xvid.h>
 #include <unistd.h>
+#if !HAVE_MKSTEMP
+#include <fcntl.h>
+#endif
+
 #include "avcodec.h"
-#include "libxvid_internal.h"
+#include "libxvid.h"
 //#include "dsputil.h"
 #include "mpegvideo.h"
 
 #undef NDEBUG
 #include <assert.h>
 
-extern unsigned int xvid_debug;
+/* Wrapper to work around the lack of mkstemp() on mingw.
+ * Also, tries to create file in /tmp first, if possible.
+ * *prefix can be a character constant; *filename will be allocated internally.
+ * @return file descriptor of opened file (or -1 on error)
+ * and opened file name in **filename. */
+int ff_tempfile(const char *prefix, char **filename) {
+    int fd=-1;
+#if !HAVE_MKSTEMP
+    *filename = tempnam(".", prefix);
+#else
+    size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
+    *filename = av_malloc(len);
+#endif
+    /* -----common section-----*/
+    if (*filename == NULL) {
+        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
+        return -1;
+    }
+#if !HAVE_MKSTEMP
+    fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
+#else
+    snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
+    fd = mkstemp(*filename);
+    if (fd < 0) {
+        snprintf(*filename, len, "./%sXXXXXX", prefix);
+        fd = mkstemp(*filename);
+    }
+#endif
+    /* -----common section-----*/
+    if (fd < 0) {
+        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
+        return -1;
+    }
+    return fd; /* success */
+}
 
 int ff_xvid_rate_control_init(MpegEncContext *s){
     char *tmp_name;
@@ -38,8 +77,6 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
     xvid_plg_create_t xvid_plg_create = { 0 };
     xvid_plugin_2pass2_t xvid_2pass2  = { 0 };
 
-//xvid_debug=-1;
-
     fd=ff_tempfile("xvidrc.", &tmp_name);
     if (fd == -1) {
         av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n");
@@ -57,7 +94,6 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
             frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count,
             rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8);
 
-//av_log(NULL, AV_LOG_ERROR, "%s\n", tmp);
         write(fd, tmp, strlen(tmp));
     }
 
@@ -101,10 +137,6 @@ float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){
     xvid_plg_data.bquant_offset = 0; //  100 * s->avctx->b_quant_offset;
     xvid_plg_data.bquant_ratio = 100; // * s->avctx->b_quant_factor;
 
-#if 0
-    xvid_plg_data.stats.hlength= X
-#endif
-
     if(!s->rc_context.dry_run_qscale){
         if(s->picture_number){
             xvid_plg_data.length=