OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / libhb / decutf8sub.c
1 /* 
2    This file is part of the HandBrake source code.
3    Homepage: <http://handbrake.fr/>.
4    It may be used under the terms of the GNU General Public License. */
5
6 /*
7  * Decoder for UTF-8 subtitles obtained from file input-sources.
8  * 
9  * Input and output packet format is UTF-8 encoded text,
10  * with limited HTML-style markup (only <b>, <i>, and <u>).
11  * 
12  * @author David Foster (davidfstr)
13  */
14
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include "hb.h"
18
19 static int decutf8Init( hb_work_object_t * w, hb_job_t * job )
20 {
21     return 0;
22 }
23
24 static int decutf8Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
25                         hb_buffer_t ** buf_out )
26 {
27     hb_buffer_t * in = *buf_in;
28     hb_buffer_t * out = NULL;
29
30     // Pass the packets through without modification
31     out = in;
32
33     // Warn if the subtitle's duration has not been passed through by the demuxer,
34     // which will prevent the subtitle from displaying at all
35     if ( out->stop == 0 ) {
36         hb_log( "decutf8sub: subtitle packet lacks duration" );
37     }
38     
39     // We shouldn't be storing the extra NULL character,
40     // but the MP4 muxer expects this, unfortunately.
41     if ( out->size > 0 && out->data[out->size - 1] != '\0' ) {
42         // NOTE: out->size remains unchanged
43         hb_buffer_realloc( out, out->size + 1 );
44         out->data[out->size] = '\0';
45     }
46     
47     *buf_in = NULL;
48     *buf_out = out;
49     return HB_WORK_OK;
50 }
51
52 static void decutf8Close( hb_work_object_t * w )
53 {
54     // nothing
55 }
56
57 hb_work_object_t hb_decutf8sub =
58 {
59     WORK_DECUTF8SUB,
60     "UTF-8 Subtitle Decoder",
61     decutf8Init,
62     decutf8Work,
63     decutf8Close
64 };