OSDN Git Service

Don't drop subtitles when crossing PTS discontinuities by using buffer sequence numbe...
[handbrake-jp/handbrake-jp-git.git] / libhb / declpcm.c
1 /* $Id: declpcm.c,v 1.8 2005/11/04 14:44:01 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.m0k.org/>.
5    It may be used under the terms of the GNU General Public License. */
6
7 #include "hb.h"
8
9 int  declpcmInit( hb_work_object_t *, hb_job_t * );
10 int  declpcmWork( hb_work_object_t *, hb_buffer_t **, hb_buffer_t ** );
11 void declpcmClose( hb_work_object_t * );
12
13 hb_work_object_t hb_declpcm =
14 {   
15     WORK_DECLPCM,
16     "LPCM decoder",
17     declpcmInit,
18     declpcmWork,
19     declpcmClose
20 };
21
22 int declpcmInit( hb_work_object_t * w, hb_job_t * job )
23 {
24     return 0;
25 }
26
27 int declpcmWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
28                  hb_buffer_t ** buf_out )
29 {
30     hb_buffer_t * in = *buf_in, * out;
31     int samplerate = 0;
32     int count;
33     uint8_t * samples_u8;
34     float   * samples_fl32;
35     int i;
36     uint64_t duration;
37
38     *buf_out = NULL;
39
40     if( in->data[5] != 0x80 )
41     {
42         hb_log( "no LPCM frame sync (%02x)", in->data[5] );
43         return HB_WORK_OK;
44     }
45
46     switch( ( in->data[4] >> 4 ) & 0x3 )
47     {
48         case 0:
49             samplerate = 48000;
50             break;
51         case 1:
52             samplerate = 96000;//32000; /* FIXME vlc says it is 96000 */
53             break;
54         case 2:
55             samplerate = 44100;
56             break;
57         case 3:
58             samplerate = 32000;
59             break;
60     }
61
62     count       = ( in->size - 6 ) / 2;
63     out         = hb_buffer_init( count * sizeof( float ) );
64     duration    = count * 90000 / samplerate / 2;
65     out->start  = in->start;
66     out->stop   = out->start + duration;
67
68     samples_u8   = in->data + 6;
69     samples_fl32 = (float *) out->data;
70
71     /* Big endian int16 -> float conversion */
72     for( i = 0; i < count; i++ )
73     {
74 #ifdef WORDS_BIGENDIAN
75         samples_fl32[0] = *( (int16_t *) samples_u8 );
76 #else
77         samples_fl32[0] = (int16_t) ( ( samples_u8[0] << 8 ) | samples_u8[1] );
78 #endif
79         samples_u8   += 2;
80         samples_fl32 += 1;
81     }
82
83     *buf_out = out;
84
85     return HB_WORK_OK;
86 }
87
88 void declpcmClose( hb_work_object_t * w )
89 {
90 }