]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cap_ogg.c
Fix engine not starting on Windows if linked against SDL > 2.0.5
[xonotic/darkplaces.git] / cap_ogg.c
index ff4bfb60729690a0cb84e6f18063d87fec24c874..e9abc7ae573fa143a1be388d64f3a64466451291 100644 (file)
--- a/cap_ogg.c
+++ b/cap_ogg.c
@@ -9,8 +9,8 @@
 
 // video capture cvars
 static cvar_t cl_capturevideo_ogg_theora_vp3compat = {CVAR_SAVE, "cl_capturevideo_ogg_theora_vp3compat", "1", "make VP3 compatible theora streams"};
-static cvar_t cl_capturevideo_ogg_theora_quality = {CVAR_SAVE, "cl_capturevideo_ogg_theora_quality", "42", "video quality factor (0 to 63), or -1 to use bitrate only; higher is better"};
-static cvar_t cl_capturevideo_ogg_theora_bitrate = {CVAR_SAVE, "cl_capturevideo_ogg_theora_bitrate", "-1", "video bitrate (45 to 2000 kbps), or -1 to use quality only; higher is better"};
+static cvar_t cl_capturevideo_ogg_theora_quality = {CVAR_SAVE, "cl_capturevideo_ogg_theora_quality", "48", "video quality factor (0 to 63), or -1 to use bitrate only; higher is better; setting both to -1 achieves unlimited quality"};
+static cvar_t cl_capturevideo_ogg_theora_bitrate = {CVAR_SAVE, "cl_capturevideo_ogg_theora_bitrate", "-1", "video bitrate (45 to 2000 kbps), or -1 to use quality only; higher is better; setting both to -1 achieves unlimited quality"};
 static cvar_t cl_capturevideo_ogg_theora_keyframe_bitrate_multiplier = {CVAR_SAVE, "cl_capturevideo_ogg_theora_keyframe_bitrate_multiplier", "1.5", "how much more bit rate to use for keyframes, specified as a factor of at least 1"};
 static cvar_t cl_capturevideo_ogg_theora_keyframe_maxinterval = {CVAR_SAVE, "cl_capturevideo_ogg_theora_keyframe_maxinterval", "64", "maximum keyframe interval (1 to 1000)"};
 static cvar_t cl_capturevideo_ogg_theora_keyframe_mininterval = {CVAR_SAVE, "cl_capturevideo_ogg_theora_keyframe_mininterval", "8", "minimum keyframe interval (1 to 1000)"};
@@ -523,7 +523,7 @@ static dllfunction_t theorafuncs[] =
 
 static dllhandle_t og_dll = NULL, vo_dll = NULL, ve_dll = NULL, th_dll = NULL;
 
-qboolean SCR_CaptureVideo_Ogg_OpenLibrary(void)
+static qboolean SCR_CaptureVideo_Ogg_OpenLibrary(void)
 {
        const char* dllnames_og [] =
        {
@@ -677,7 +677,7 @@ static void SCR_CaptureVideo_Ogg_Interleave(void)
                                format->videopage.len = pg.header_len + pg.body_len;
                                format->videopage.time = qtheora_granule_time(&format->ts, qogg_page_granulepos(&pg));
                                if(format->videopage.len > sizeof(format->videopage.data))
-                                       Host_Error("video page too long");
+                                       Sys_Error("video page too long");
                                memcpy(format->videopage.data, pg.header, pg.header_len);
                                memcpy(format->videopage.data + pg.header_len, pg.body, pg.body_len);
                        }
@@ -687,7 +687,7 @@ static void SCR_CaptureVideo_Ogg_Interleave(void)
                                format->audiopage.len = pg.header_len + pg.body_len;
                                format->audiopage.time = qvorbis_granule_time(&format->vd, qogg_page_granulepos(&pg));
                                if(format->audiopage.len > sizeof(format->audiopage.data))
-                                       Host_Error("audio page too long");
+                                       Sys_Error("audio page too long");
                                memcpy(format->audiopage.data, pg.header, pg.header_len);
                                memcpy(format->audiopage.data + pg.header_len, pg.body, pg.body_len);
                        }
@@ -782,7 +782,7 @@ static void SCR_CaptureVideo_Ogg_EndVideo(void)
        while (1) {
                int result = qogg_stream_flush (&format->to, &pg);
                if (result < 0)
-                       fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
+                       fprintf (stderr, "Internal Ogg library error.\n"); // TODO Sys_Error
                if (result <= 0)
                        break;
                FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
@@ -794,7 +794,7 @@ static void SCR_CaptureVideo_Ogg_EndVideo(void)
                while (1) {
                        int result = qogg_stream_flush (&format->vo, &pg);
                        if (result < 0)
-                               fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
+                               fprintf (stderr, "Internal Ogg library error.\n"); // TODO Sys_Error
                        if (result <= 0)
                                break;
                        FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
@@ -828,7 +828,7 @@ static void SCR_CaptureVideo_Ogg_ConvertFrame_BGRA_to_YUV(void)
        yuv_buffer *yuv;
        int x, y;
        int blockr, blockg, blockb;
-       unsigned char *b = cls.capturevideo.outbuffer;
+       unsigned char *b;
        int w = cls.capturevideo.width;
        int h = cls.capturevideo.height;
        int inpitch = w*4;
@@ -847,7 +847,7 @@ static void SCR_CaptureVideo_Ogg_ConvertFrame_BGRA_to_YUV(void)
                        b += 4;
                }
 
-               if((y & 1) == 0)
+               if ((y & 1) == 0 && y/2 < h/2) // if h is odd, this skips the last row
                {
                        for(b = cls.capturevideo.outbuffer + (h-2-y)*w*4, x = 0; x < w/2; ++x)
                        {
@@ -914,14 +914,14 @@ static void SCR_CaptureVideo_Ogg_SoundFrame(const portable_sampleframe_t *paintb
        ogg_packet pt;
        int *map = mapping[bound(1, cls.capturevideo.soundchannels, 8) - 1];
 
-       vorbis_buffer = qvorbis_analysis_buffer(&format->vd, length);
+       vorbis_buffer = qvorbis_analysis_buffer(&format->vd, (int)length);
        for(j = 0; j < cls.capturevideo.soundchannels; ++j)
        {
                float *b = vorbis_buffer[map[j]];
                for(i = 0; i < length; ++i)
-                       b[i] = paintbuffer[i].sample[j] / 32768.0f;
+                       b[i] = paintbuffer[i].sample[j];
        }
-       qvorbis_analysis_wrote(&format->vd, length);
+       qvorbis_analysis_wrote(&format->vd, (int)length);
 
        while(qvorbis_analysis_blockout(&format->vd, &format->vb) == 1)
        {
@@ -937,9 +937,10 @@ static void SCR_CaptureVideo_Ogg_SoundFrame(const portable_sampleframe_t *paintb
 
 void SCR_CaptureVideo_Ogg_BeginVideo(void)
 {
+       char vabuf[1024];
        cls.capturevideo.format = CAPTUREVIDEOFORMAT_OGG_VORBIS_THEORA;
        cls.capturevideo.formatextension = "ogv";
-       cls.capturevideo.videofile = FS_OpenRealFile(va("%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
+       cls.capturevideo.videofile = FS_OpenRealFile(va(vabuf, sizeof(vabuf), "%s.%s", cls.capturevideo.basename, cls.capturevideo.formatextension), "wb", false);
        cls.capturevideo.endvideo = SCR_CaptureVideo_Ogg_EndVideo;
        cls.capturevideo.videoframes = SCR_CaptureVideo_Ogg_VideoFrames;
        cls.capturevideo.soundframe = SCR_CaptureVideo_Ogg_SoundFrame;
@@ -1010,32 +1011,24 @@ void SCR_CaptureVideo_Ogg_BeginVideo(void)
 
                if(ti.target_bitrate <= 0)
                {
-                       if(ti.quality < 0)
-                       {
-                               ti.target_bitrate = -1;
-                               ti.keyframe_data_target_bitrate = (unsigned int)-1;
-                               ti.quality = 63;
-                       }
-                       else
-                       {
-                               ti.target_bitrate = -1;
-                               ti.keyframe_data_target_bitrate = (unsigned int)-1;
-                               ti.quality = bound(0, ti.quality, 63);
-                       }
+                       ti.target_bitrate = -1;
+                       ti.keyframe_data_target_bitrate = (unsigned int)-1;
                }
                else
                {
-                       if(ti.quality < 0)
-                       {
-                               ti.target_bitrate = bound(45000, ti.target_bitrate, 2000000);
-                               ti.keyframe_data_target_bitrate = (int) (ti.target_bitrate * max(1, cl_capturevideo_ogg_theora_keyframe_bitrate_multiplier.value));
-                               ti.quality = -1;
-                       }
-                       else
+                       ti.keyframe_data_target_bitrate = (int) (ti.target_bitrate * max(1, cl_capturevideo_ogg_theora_keyframe_bitrate_multiplier.value));
+
+                       if(ti.target_bitrate < 45000 || ti.target_bitrate > 2000000)
+                               Con_DPrintf("WARNING: requesting an odd bitrate for theora (sensible values range from 45 to 2000 kbps)\n");
+               }
+
+               if(ti.quality < 0 || ti.quality > 63)
+               {
+                       ti.quality = 63;
+                       if(ti.target_bitrate <= 0)
                        {
-                               ti.target_bitrate = bound(45000, ti.target_bitrate, 2000000);
-                               ti.keyframe_data_target_bitrate = (int) (ti.target_bitrate * max(1, cl_capturevideo_ogg_theora_keyframe_bitrate_multiplier.value));
-                               ti.quality = -1;
+                               ti.target_bitrate = 0x7FFFFFFF;
+                               ti.keyframe_data_target_bitrate = 0x7FFFFFFF;
                        }
                }
 
@@ -1106,7 +1099,7 @@ void SCR_CaptureVideo_Ogg_BeginVideo(void)
                {
                        int result = qogg_stream_flush (&format->to, &pg);
                        if (result < 0)
-                               fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
+                               fprintf (stderr, "Internal Ogg library error.\n"); // TODO Sys_Error
                        if (result <= 0)
                                break;
                        FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);
@@ -1118,7 +1111,7 @@ void SCR_CaptureVideo_Ogg_BeginVideo(void)
                {
                        int result = qogg_stream_flush (&format->vo, &pg);
                        if (result < 0)
-                               fprintf (stderr, "Internal Ogg library error.\n"); // TODO Host_Error
+                               fprintf (stderr, "Internal Ogg library error.\n"); // TODO Sys_Error
                        if (result <= 0)
                                break;
                        FS_Write(cls.capturevideo.videofile, pg.header, pg.header_len);