]> git.sesse.net Git - vlc/commitdiff
Merge branch 'master' into lpcm_encoder
authorSteinar H. Gunderson <steinar+vlc@gunderson.no>
Sat, 2 Oct 2010 00:19:09 +0000 (02:19 +0200)
committerSteinar H. Gunderson <steinar+vlc@gunderson.no>
Sat, 2 Oct 2010 00:19:09 +0000 (02:19 +0200)
include/vlc_fourcc.h
modules/access/decklink.cpp
modules/misc/freetype.c
modules/packetizer/h264.c
src/misc/mtime.c

index fd7d24a861fa4ff6115b447bdbd711589d59061e..f36651f99e486ecb1c7494852632a3465a33d00f 100644 (file)
 /* Palettized RGB with palette element R:G:B */
 #define VLC_CODEC_RGBP      VLC_FOURCC('R','G','B','P')
 /* 8 bits RGB */
-#define VLC_CODEC_RGB8      VLC_FOURCC('R','G','B','2')
+#define VLC_CODEC_RGB8      VLC_FOURCC('R','G','B','8')
 /* 15 bits RGB stored on 16 bits */
 #define VLC_CODEC_RGB15     VLC_FOURCC('R','V','1','5')
 /* 16 bits RGB store on a 16 bits */
index 87bf5237ced44d77c7dceb0bef416807186b439a..60e8b831a41532c87f71e973d10b19b005d87e2f 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * decklink.cpp: BlackMagic DeckLink SDI input module
  *****************************************************************************
- * Copyright (C) 2010 VideoLAN
+ * Copyright (C) 2010 Steinar H. Gunderson
  *
  * Authors: Steinar H. Gunderson <steinar+vlc@gunderson.no>
  *
@@ -9,34 +9,27 @@
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  *****************************************************************************/
 
+#define __STDC_CONSTANT_MACROS 1
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
-#ifndef INT64_C
-#define INT64_C(c) c ## LL
-#endif
-
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_input.h>
 #include <vlc_demux.h>
-#include <vlc_access.h>
-#include <vlc_picture.h>
-#include <vlc_charset.h>
-#include <vlc_fs.h>
 #include <vlc_atomic.h>
 
 #include <arpa/inet.h>
@@ -134,10 +127,8 @@ struct demux_sys_t
     bool b_first_frame;
     int i_last_pts;
 
-    int i_width, i_height, i_fps_num, i_fps_den;
     uint32_t i_dominance_flags;
-
-    int i_rate, i_channels;
+    int i_channels;
 
     vlc_mutex_t frame_lock;
     block_t *p_video_frame;  /* protected by <frame_lock> */
@@ -168,7 +159,12 @@ public:
         return new_ref;
     }
 
-    virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
+    virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags)
+    {
+        msg_Dbg( p_demux_, "Video input format changed" );
+        return S_OK;
+    }
+
     virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
 
 private:
@@ -176,12 +172,6 @@ private:
     demux_t *p_demux_;
 };
 
-HRESULT DeckLinkCaptureDelegate::VideoInputFormatChanged(BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *mode, BMDDetectedVideoInputFormatFlags)
-{
-    msg_Dbg( p_demux_, "Video input format changed" );
-    return S_OK;
-}
-
 HRESULT DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame* videoFrame, IDeckLinkAudioInputPacket* audioFrame)
 {
     demux_sys_t *p_sys = p_demux_->p_sys;
@@ -213,18 +203,13 @@ HRESULT DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame
         for( int y = 0; y < i_height; ++y )
         {
             const uint8_t *src = (const uint8_t *)frame_bytes + i_stride * y;
-            uint8_t *dst = (uint8_t *)p_video_frame->p_buffer + i_width * i_bpp * y;
+            uint8_t *dst = p_video_frame->p_buffer + i_width * i_bpp * y;
             memcpy( dst, src, i_width * i_bpp );
         }
 
         BMDTimeValue stream_time, frame_duration;
         videoFrame->GetStreamTime( &stream_time, &frame_duration, CLOCK_FREQ );
         p_video_frame->i_flags = BLOCK_FLAG_TYPE_I | p_sys->i_dominance_flags;
-        if( p_sys->b_first_frame )
-        {
-            p_video_frame->i_flags |= BLOCK_FLAG_DISCONTINUITY;
-            p_sys->b_first_frame = false;
-        }
         p_video_frame->i_pts = p_video_frame->i_dts = VLC_TS_0 + stream_time;
     }
 
@@ -276,13 +261,16 @@ static int Open( vlc_object_t *p_this )
 {
     demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
-    int         ret = VLC_SUCCESS;
+    int         ret = VLC_EGENERIC;
     char        *psz_aspect;
     char        *psz_display_mode = NULL;
     char        *psz_video_connection = NULL;
     char        *psz_audio_connection = NULL;
     bool        b_found_mode;
     int         i_card_index;
+    int         i_width, i_height, i_fps_num, i_fps_den;
+    int         i_rate;
+    unsigned    u_aspect_num, u_aspect_den;
 
     /* Only when selected */
     if( *p_demux->psz_access == '\0' )
@@ -306,13 +294,18 @@ static int Open( vlc_object_t *p_this )
     if( !decklink_iterator )
     {
         msg_Err( p_demux, "DeckLink drivers not found." );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
     HRESULT result;
 
     i_card_index = var_InheritInteger( p_demux, "decklink-card-index" );
+    if( i_card_index < 0 )
+    {
+        msg_Err( p_demux, "Invalid card index %d", i_card_index );
+        goto finish;
+    }
+
     for( int i = 0; i <= i_card_index; ++i )
     {
         if( p_sys->p_card )
@@ -325,7 +318,6 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "DeckLink PCI card %d not found", i_card_index );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -335,7 +327,6 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "Could not get model name" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -344,7 +335,6 @@ static int Open( vlc_object_t *p_this )
     if( p_sys->p_card->QueryInterface( IID_IDeckLinkInput, (void**)&p_sys->p_input) != S_OK )
     {
         msg_Err( p_demux, "Card has no inputs" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -353,7 +343,6 @@ static int Open( vlc_object_t *p_this )
     if( p_sys->p_card->QueryInterface( IID_IDeckLinkConfiguration, (void**)&p_config) != S_OK )
     {
         msg_Err( p_demux, "Failed to get configuration interface" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -377,7 +366,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Invalid --decklink-video-connection specified; choose one of " \
                               "sdi, hdmi, opticalsdi, component, composite, or svideo." );
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -386,7 +374,6 @@ static int Open( vlc_object_t *p_this )
         if( result != S_OK )
         {
             msg_Err( p_demux, "Failed to set video input connection" );
-            ret = VLC_EGENERIC;
             goto finish;
         }
     }
@@ -405,7 +392,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Invalid --decklink-audio-connection specified; choose one of " \
                               "embedded, aesebu, or analog." );
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -414,7 +400,6 @@ static int Open( vlc_object_t *p_this )
         if( result != S_OK )
         {
             msg_Err( p_demux, "Failed to set audio input connection" );
-            ret = VLC_EGENERIC;
             goto finish;
         }
     }
@@ -425,14 +410,12 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "Failed to enumerate display modes" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
-    psz_display_mode = var_InheritString( p_demux, "decklink-mode" );
-    if( !psz_display_mode || strlen( psz_display_mode ) == 0 || strlen( psz_display_mode ) > 4 ) {
+    psz_display_mode = var_CreateGetNonEmptyString( p_demux, "decklink-mode" );
+    if( !psz_display_mode || strlen( psz_display_mode ) > 4 ) {
         msg_Err( p_demux, "Missing or invalid --decklink-mode string" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -467,7 +450,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Failed to get display mode name" );
             p_display_mode->Release();
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -477,7 +459,6 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Err( p_demux, "Failed to get frame rate" );
             p_display_mode->Release();
-            ret = VLC_EGENERIC;
             goto finish;
         }
 
@@ -513,10 +494,10 @@ static int Open( vlc_object_t *p_this )
         if( wanted_mode_id == mode_id )
         {
             b_found_mode = true;
-            p_sys->i_width = p_display_mode->GetWidth();
-            p_sys->i_height = p_display_mode->GetHeight();
-            p_sys->i_fps_num = time_scale;
-            p_sys->i_fps_den = frame_duration;
+            i_width = p_display_mode->GetWidth();
+            i_height = p_display_mode->GetHeight();
+            i_fps_num = time_scale;
+            i_fps_den = frame_duration;
             p_sys->i_dominance_flags = i_dominance_flags;
         }
 
@@ -528,7 +509,6 @@ static int Open( vlc_object_t *p_this )
         msg_Err( p_demux, "Unknown video mode specified. " \
                           "Run VLC with -v --verbose-objects=-all,+decklink " \
                           "to get a list of supported modes." );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
@@ -536,20 +516,18 @@ static int Open( vlc_object_t *p_this )
     if( result != S_OK )
     {
         msg_Err( p_demux, "Failed to enable video input" );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
     /* Set up audio. */
-    p_sys->i_rate = var_InheritInteger( p_demux, "decklink-audio-rate" );
     p_sys->i_channels = var_InheritInteger( p_demux, "decklink-audio-channels" );
-    if( p_sys->i_rate > 0 && p_sys->i_channels > 0 )
+    i_rate = var_InheritInteger( p_demux, "decklink-audio-rate" );
+    if( i_rate > 0 && p_sys->i_channels > 0 )
     {
-        result = p_sys->p_input->EnableAudioInput( p_sys->i_rate, bmdAudioSampleType16bitInteger, p_sys->i_channels );
+        result = p_sys->p_input->EnableAudioInput( i_rate, bmdAudioSampleType16bitInteger, p_sys->i_channels );
         if( result != S_OK )
         {
             msg_Err( p_demux, "Failed to enable audio input" );
-            ret = VLC_EGENERIC;
             goto finish;
         }
     }
@@ -562,32 +540,24 @@ static int Open( vlc_object_t *p_this )
     {
         msg_Err( p_demux, "Could not start streaming from SDI card. This could be caused "
                           "by invalid video mode or flags, access denied, or card already in use." );
-        ret = VLC_EGENERIC;
         goto finish;
     }
 
     /* Declare elementary streams */
     es_format_t video_fmt;
     es_format_Init( &video_fmt, VIDEO_ES, VLC_CODEC_UYVY );
-    video_fmt.video.i_width = p_sys->i_width;
-    video_fmt.video.i_height = p_sys->i_height;
+    video_fmt.video.i_width = i_width;
+    video_fmt.video.i_height = i_height;
     video_fmt.video.i_sar_num = 1;
     video_fmt.video.i_sar_den = 1;
-    video_fmt.video.i_frame_rate = p_sys->i_fps_num;
-    video_fmt.video.i_frame_rate_base = p_sys->i_fps_den;
+    video_fmt.video.i_frame_rate = i_fps_num;
+    video_fmt.video.i_frame_rate_base = i_fps_den;
     video_fmt.i_bitrate = video_fmt.video.i_width * video_fmt.video.i_height * video_fmt.video.i_frame_rate * 2 * 8;
 
-    psz_aspect = var_CreateGetNonEmptyString( p_demux, "decklink-aspect-ratio" );
-    if( psz_aspect )
-    {
-        char *psz_denominator = strchr( psz_aspect, ':' );
-        if( psz_denominator )
-        {
-            *psz_denominator++ = '\0';
-            video_fmt.video.i_sar_num = atoi( psz_aspect )      * video_fmt.video.i_height;
-            video_fmt.video.i_sar_den = atoi( psz_denominator ) * video_fmt.video.i_width;
-        }
-        free( psz_aspect );
+    if ( !var_InheritURational( p_demux, &u_aspect_num, &u_aspect_den, "decklink-aspect-ratio" ) &&
+         u_aspect_num > 0 && u_aspect_den > 0 ) {
+        video_fmt.video.i_sar_num = u_aspect_num * video_fmt.video.i_height;
+        video_fmt.video.i_sar_den = u_aspect_den * video_fmt.video.i_width;
     }
 
     msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
@@ -597,7 +567,7 @@ static int Open( vlc_object_t *p_this )
     es_format_t audio_fmt;
     es_format_Init( &audio_fmt, AUDIO_ES, VLC_CODEC_S16N );
     audio_fmt.audio.i_channels = p_sys->i_channels;
-    audio_fmt.audio.i_rate = p_sys->i_rate;
+    audio_fmt.audio.i_rate = i_rate;
     audio_fmt.audio.i_bitspersample = 16;
     audio_fmt.audio.i_blockalign = audio_fmt.audio.i_channels * audio_fmt.audio.i_bitspersample / 8;
     audio_fmt.i_bitrate = audio_fmt.audio.i_channels * audio_fmt.audio.i_rate * audio_fmt.audio.i_bitspersample;
@@ -606,8 +576,7 @@ static int Open( vlc_object_t *p_this )
              (char*)&audio_fmt.i_codec, audio_fmt.audio.i_rate, audio_fmt.audio.i_bitspersample, audio_fmt.audio.i_channels);
     p_sys->p_audio_es = es_out_Add( p_demux->out, &audio_fmt );
 
-    /* Update default_pts to a suitable value for access */
-    var_Create( p_demux, "decklink-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    ret = VLC_SUCCESS;
 
 finish:
     if( decklink_iterator )
@@ -673,7 +642,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_PTS_DELAY:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = var_GetInteger( p_demux, "decklink-caching" ) * 1000;
+            *pi64 = var_InheritInteger( p_demux, "decklink-caching" ) * 1000;
             return VLC_SUCCESS;
 
         case DEMUX_GET_TIME:
index 7d6c4f6b661bdf2f32bc322fc25296ff25100c3a..e39d8afe595944438bc45bd81a4b3531480603ac 100644 (file)
@@ -316,12 +316,12 @@ static int Create( vlc_object_t *p_this )
     var_Create( p_filter, "freetype-rel-fontsize",
                 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
 
-    psz_fontfamily = var_CreateGetString( p_filter, "freetype-font" );
-    p_sys->i_default_font_size = var_CreateGetInteger( p_filter, "freetype-fontsize" );
-    p_sys->i_effect = var_CreateGetInteger( p_filter, "freetype-effect" );
-    p_sys->i_font_opacity = var_CreateGetInteger( p_filter,"freetype-opacity" );
+    psz_fontfamily = var_InheritString( p_filter, "freetype-font" );
+    p_sys->i_default_font_size = var_InheritInteger( p_filter, "freetype-fontsize" );
+    p_sys->i_effect = var_InheritInteger( p_filter, "freetype-effect" );
+    p_sys->i_font_opacity = var_InheritInteger( p_filter,"freetype-opacity" );
     p_sys->i_font_opacity = __MAX( __MIN( p_sys->i_font_opacity, 255 ), 0 );
-    p_sys->i_font_color = var_CreateGetInteger( p_filter, "freetype-color" );
+    p_sys->i_font_color = var_InheritInteger( p_filter, "freetype-color" );
     p_sys->i_font_color = __MAX( __MIN( p_sys->i_font_color , 0xFFFFFF ), 0 );
 
     fontindex=0;
@@ -479,11 +479,11 @@ error:
 #ifdef HAVE_FONTCONFIG
     if( fontmatch ) FcPatternDestroy( fontmatch );
     if( fontpattern ) FcPatternDestroy( fontpattern );
-#endif
 
 #ifdef WIN32
     if( p_dialog )
         dialog_ProgressDestroy( p_dialog );
+#endif
 #endif
 
     if( p_sys->p_face ) FT_Done_Face( p_sys->p_face );
index 35e101026a268c970bfacc89292387aeb43aa8c5..0b8de454ebcd6c1c2dae4b4d20023b26f5591d99 100644 (file)
@@ -101,6 +101,7 @@ struct decoder_sys_t
     bool   b_pps;
     block_t *pp_sps[SPS_MAX];
     block_t *pp_pps[PPS_MAX];
+    int    i_recovery_frames;  /* -1 = no recovery */
 
     /* avcC data */
     int i_avcC_length_size;
@@ -217,6 +218,7 @@ static int Open( vlc_object_t *p_this )
         p_sys->pp_sps[i] = NULL;
     for( i = 0; i < PPS_MAX; i++ )
         p_sys->pp_pps[i] = NULL;
+    p_sys->i_recovery_frames = -1;
 
     p_sys->slice.i_nal_type = -1;
     p_sys->slice.i_nal_ref_idc = -1;
@@ -699,7 +701,7 @@ static block_t *ParseNALBlock( decoder_t *p_dec, bool *pb_used_ts, block_t *p_fr
         block_ChainAppend( &p_sys->p_frame, p_frag );
 
     *pb_used_ts = false;
-    if( p_sys->i_frame_dts <= VLC_TS_INVALID && 
+    if( p_sys->i_frame_dts <= VLC_TS_INVALID &&
         p_sys->i_frame_pts <= VLC_TS_INVALID )
     {
         p_sys->i_frame_dts = i_frag_dts;
@@ -714,7 +716,18 @@ static block_t *OutputPicture( decoder_t *p_dec )
     decoder_sys_t *p_sys = p_dec->p_sys;
     block_t *p_pic;
 
-    if( !p_sys->b_header && p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I)
+    if ( !p_sys->b_header && p_sys->i_recovery_frames != -1 )
+    {
+        if( p_sys->i_recovery_frames == 0 )
+        {
+            msg_Dbg( p_dec, "Recovery from SEI recovery point complete" );
+            p_sys->b_header = true;
+        }
+        --p_sys->i_recovery_frames;
+    }
+
+    if( !p_sys->b_header && p_sys->i_recovery_frames == -1 &&
+         p_sys->slice.i_frame_type != BLOCK_FLAG_TYPE_I)
         return NULL;
 
     const bool b_sps_pps_i = p_sys->slice.i_frame_type == BLOCK_FLAG_TYPE_I &&
@@ -760,6 +773,8 @@ static block_t *OutputPicture( decoder_t *p_dec )
     p_pic->i_length = 0;    /* FIXME */
     p_pic->i_flags |= p_sys->slice.i_frame_type;
     p_pic->i_flags &= ~BLOCK_FLAG_PRIVATE_AUD;
+    if( !p_sys->b_header )
+        p_pic->i_flags |= BLOCK_FLAG_PREROLL;
 
     p_sys->slice.i_frame_type = 0;
     p_sys->p_frame = NULL;
@@ -1176,6 +1191,27 @@ static void ParseSei( decoder_t *p_dec, block_t *p_frag )
                 cc_Extract( &p_sys->cc_next, true, &p_t35[3], i_t35 - 3 );
             }
         }
+
+        /* Look for SEI recovery point */
+        if( i_type == 6 )
+        {
+            bs_t s;
+            const int      i_rec = i_size;
+            const uint8_t *p_rec = &pb_dec[i_used];
+
+            bs_init( &s, p_rec, i_rec );
+            int i_recovery_frames = bs_read_ue( &s );
+            //bool b_exact_match = bs_read( &s, 1 );
+            //bool b_broken_link = bs_read( &s, 1 );
+            //int i_changing_slice_group = bs_read( &s, 2 );
+            if( !p_sys->b_header )
+            {
+                msg_Dbg( p_dec, "Seen SEI recovery point, %d recovery frames", i_recovery_frames );
+                if ( p_sys->i_recovery_frames == -1 || i_recovery_frames < p_sys->i_recovery_frames )
+                    p_sys->i_recovery_frames = i_recovery_frames;
+            }
+        }
+
         i_used += i_size;
     }
 
index 80ed1169ee3f3eb39967d1be350f1ee592cd8484..115dbe9ffc6cce42a2ef2e9a5dde211a035b9fd1 100644 (file)
@@ -216,11 +216,16 @@ mtime_t mdate( void )
     uint64_t date = mach_absolute_time();
     mach_timebase_info_data_t tb = mtime_timebase_info;
 
-    /* Get the ssystem dependent factor. Switch to double to prevent overflow */
-    double factor = (double) tb.numer / (double) tb.denom;
-    /* Convert to microseconds */
-    double d = (double) date * factor / 1000;
-    res = d;
+    /* tb.denom is uint32_t, switch to 64 bits to prevent overflow. */
+    uint64_t denom = tb.denom;
+
+    /* Switch to microsecs */
+    denom *= 1000LL;
+
+    /* Split the division to prevent overflow */
+    lldiv_t d = lldiv (tb.numer, denom);
+
+    res = (d.quot * date) + ((d.rem * date) / denom);
 
 #elif defined( WIN32 ) || defined( UNDER_CE )
     /* We don't need the real date, just the value of a high precision timer */