-/* */
-static ass_handle_t *AssHandleHold( decoder_t *p_dec )
-{
- vlc_mutex_lock( &libass_lock );
-
- ass_handle_t *p_ass = NULL;
- ASS_Library *p_library = NULL;
- ASS_Renderer *p_renderer = NULL;
- vlc_value_t val;
-
- var_Create( p_dec->p_libvlc, "libass-handle", VLC_VAR_ADDRESS );
- if( var_Get( p_dec->p_libvlc, "libass-handle", &val ) )
- val.p_address = NULL;
-
- if( val.p_address )
- {
- p_ass = val.p_address;
-
- p_ass->i_refcount++;
-
- vlc_mutex_unlock( &libass_lock );
- return p_ass;
- }
-
- /* */
- p_ass = malloc( sizeof(*p_ass) );
- if( !p_ass )
- goto error;
-
- /* */
- p_ass->p_libvlc = VLC_OBJECT(p_dec->p_libvlc);
- p_ass->i_refcount = 1;
-
- /* Create libass library */
- p_ass->p_library = p_library = ass_library_init();
- if( !p_library )
- goto error;
-
- /* load attachments */
- input_attachment_t **pp_attachments;
- int i_attachments;
-
- if( decoder_GetInputAttachments( p_dec, &pp_attachments, &i_attachments ))
- {
- i_attachments = 0;
- pp_attachments = NULL;
- }
- for( int k = 0; k < i_attachments; k++ )
- {
- input_attachment_t *p_attach = pp_attachments[k];
-
- if( !strcasecmp( p_attach->psz_mime, "application/x-truetype-font" ) )
- {
- msg_Dbg( p_dec, "adding embedded font %s", p_attach->psz_name );
-
- ass_add_font( p_ass->p_library, p_attach->psz_name, p_attach->p_data, p_attach->i_data );
- }
- vlc_input_attachment_Delete( p_attach );
- }
- free( pp_attachments );
-
- ass_set_extract_fonts( p_library, true );
- ass_set_style_overrides( p_library, NULL );
-
- /* Create the renderer */
- p_ass->p_renderer = p_renderer = ass_renderer_init( p_library );
- if( !p_renderer )
- goto error;
-
- ass_set_use_margins( p_renderer, false);
- //if( false )
- // ass_set_margins( p_renderer, int t, int b, int l, int r);
- ass_set_hinting( p_renderer, ASS_HINTING_LIGHT );
- ass_set_font_scale( p_renderer, 1.0 );
- ass_set_line_spacing( p_renderer, 0.0 );
-
- const char *psz_font = NULL; /* We don't ship a default font with VLC */
- const char *psz_family = "Arial"; /* Use Arial if we can't find anything more suitable */
-
-#ifdef HAVE_FONTCONFIG
-#if defined(WIN32)
- dialog_progress_bar_t *p_dialog = dialog_ProgressCreate( p_dec,
- _("Building font cache"),
- _( "Please wait while your font cache is rebuilt.\n"
- "This should take less than a minute." ), NULL );
- if( p_dialog )
- dialog_ProgressSet( p_dialog, NULL, 0.2 );
-#endif
- ass_set_fonts( p_renderer, psz_font, psz_family, true, NULL, 1 ); // setup default font/family
-#ifdef WIN32
- if( p_dialog )
- {
- dialog_ProgressSet( p_dialog, NULL, 1.0 );
- dialog_ProgressDestroy( p_dialog );
- p_dialog = NULL;
- }
-#endif
-#else
- /* FIXME you HAVE to give him a font if no fontconfig */
- ass_set_fonts( p_renderer, psz_font, psz_family, false, NULL, 1 );
-#endif
- memset( &p_ass->fmt, 0, sizeof(p_ass->fmt) );
-
- /* */
- val.p_address = p_ass;
- var_Set( p_dec->p_libvlc, "libass-handle", val );
-
- /* */
- vlc_mutex_unlock( &libass_lock );
- return p_ass;
-
-error:
- if( p_renderer )
- ass_renderer_done( p_renderer );
- if( p_library )
- ass_library_done( p_library );
-
- msg_Warn( p_dec, "Libass creation failed" );
-
- free( p_ass );
- vlc_mutex_unlock( &libass_lock );
- return NULL;
-}
-static void AssHandleRelease( ass_handle_t *p_ass )
-{
- vlc_mutex_lock( &libass_lock );
- p_ass->i_refcount--;
- if( p_ass->i_refcount > 0 )
- {
- vlc_mutex_unlock( &libass_lock );
- return;
- }
-
- ass_renderer_done( p_ass->p_renderer );
- ass_library_done( p_ass->p_library );
-
- vlc_value_t val;
- val.p_address = NULL;
- var_Set( p_ass->p_libvlc, "libass-handle", val );
-
- vlc_mutex_unlock( &libass_lock );
- free( p_ass );
-}