]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libxvid_rc.c
configure: Identify icc compiler with a less ambiguous pattern
[ffmpeg] / libavcodec / libxvid_rc.c
index 2386ce3cc63c15d394a363e99ac38fd947f3d74f..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;
     int fd, i;
-    xvid_plg_create_t xvid_plg_create;
-    xvid_plugin_2pass2_t xvid_2pass2;
-
-//xvid_debug=-1;
+    xvid_plg_create_t xvid_plg_create = { 0 };
+    xvid_plugin_2pass2_t xvid_2pass2  = { 0 };
 
     fd=ff_tempfile("xvidrc.", &tmp_name);
     if (fd == -1) {
@@ -47,7 +84,7 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
     }
 
     for(i=0; i<s->rc_context.num_entries; i++){
-        static const char *frame_types = " ipbs";
+        static const char frame_types[] = " ipbs";
         char tmp[256];
         RateControlEntry *rce;
 
@@ -57,13 +94,11 @@ 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));
     }
 
     close(fd);
 
-    memset(&xvid_2pass2, 0, sizeof(xvid_2pass2));
     xvid_2pass2.version= XVID_MAKE_VERSION(1,1,0);
     xvid_2pass2.filename= tmp_name;
     xvid_2pass2.bitrate= s->avctx->bit_rate;
@@ -71,7 +106,6 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
     xvid_2pass2.vbv_maxrate= s->avctx->rc_max_rate;
     xvid_2pass2.vbv_initial= s->avctx->rc_initial_buffer_occupancy;
 
-    memset(&xvid_plg_create, 0, sizeof(xvid_plg_create));
     xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0);
     xvid_plg_create.fbase= s->avctx->time_base.den;
     xvid_plg_create.fincr= s->avctx->time_base.num;
@@ -85,9 +119,8 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
 }
 
 float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){
-    xvid_plg_data_t xvid_plg_data;
+    xvid_plg_data_t xvid_plg_data = { 0 };
 
-    memset(&xvid_plg_data, 0, sizeof(xvid_plg_data));
     xvid_plg_data.version= XVID_MAKE_VERSION(1,1,0);
     xvid_plg_data.width = s->width;
     xvid_plg_data.height= s->height;
@@ -104,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=