~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_audio/ADM_dcainfo.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-12-15 17:13:20 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215171320-w79pvpehxx2fr217
Tags: 1:2.3.0-0.0ubuntu1
* Merge from debian-multimedia.org, remaining Ubuntu change:
  - desktop file,
  - no support for ccache and make -j.
* Closes Ubuntu: #69614.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: ADM_a52info
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: mean <fixounet@free.fr>, (C) 2004
 
8
//
 
9
// Copyright: See COPYING file that comes with this distribution
 
10
//
 
11
//
 
12
 
 
13
#include "config.h"
 
14
#include <stdio.h>
 
15
#include "ADM_library/default.h"
 
16
#include "ADM_audio/ADM_dcainfo.h"
 
17
#include "ADM_assert.h"
 
18
extern "C"
 
19
{
 
20
#include "common.h"
 
21
#include "bswap.h"
 
22
#include "ADM_lavcodec/bitstream.h"
 
23
 
 
24
}
 
25
 
 
26
/*
 
27
        Borrowed from libdca
 
28
*/
 
29
static const int dts_sample_rates[] =
 
30
{
 
31
    0, 8000, 16000, 32000, 0, 0, 11025, 22050, 44100, 0, 0,
 
32
    12000, 24000, 48000, 96000, 192000
 
33
};
 
34
 
 
35
static const int dts_bit_rates[] =
 
36
{
 
37
    32000, 56000, 64000, 96000, 112000, 128000,
 
38
    192000, 224000, 256000, 320000, 384000,
 
39
    448000, 512000, 576000, 640000, 768000,
 
40
    896000, 1024000, 1152000, 1280000, 1344000,
 
41
    1408000, 1411200, 1472000, 1536000, 1920000,
 
42
    2048000, 3072000, 3840000, 1/*open*/, 2/*variable*/, 3/*lossless*/
 
43
};
 
44
 
 
45
static const uint8_t dts_channels[] =
 
46
{
 
47
    1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8
 
48
};
 
49
 
 
50
/*
 
51
    Return frame size
 
52
*/
 
53
int  ADM_DCAGetInfo(uint8_t *buf, uint32_t len, uint32_t *fq, uint32_t *br, uint32_t *chan,uint32_t *syncoff,uint32_t *flagso,uint32_t *nbSample)
 
54
{
 
55
uint8_t *end=buf+len-4-DTS_HEADER_SIZE;
 
56
uint8_t *cur=buf-1;
 
57
uint32_t size,len1,len2,flags,sr,framesize=0,index,nbBlocks;
 
58
             // Assume 16 bits big endian
 
59
            // Search for 7F FE 80 01 as sync start
 
60
            *syncoff=0;
 
61
            while(cur<end)
 
62
            {
 
63
                cur++;
 
64
                if(*cur!=0x7F) continue;
 
65
                if(cur[1]!=0xfe) continue;
 
66
                if(cur[2]!=0x80) continue;
 
67
                if(cur[3]!=0x01) continue;
 
68
                // ok we got a starcode
 
69
                // State :      32 bits, already got them
 
70
                // Frame type   1 
 
71
                // Sample Deficit 5
 
72
                // CRC present  1
 
73
                // Frame length  7
 
74
                // Frame Size 14
 
75
                // **** Inefficient ! ****
 
76
                GetBitContext s;
 
77
                init_get_bits( &s,cur, (end-cur)*8);
 
78
                skip_bits(&s,32);
 
79
                skip_bits(&s,1);
 
80
                skip_bits(&s,5);
 
81
                skip_bits(&s,1);
 
82
                //Nb Samples
 
83
                nbBlocks=(get_bits(&s,7)+1);
 
84
                // Frame size in bit
 
85
                len2=get_bits(&s,14);
 
86
                framesize=len2+1;
 
87
                //
 
88
                //  
 
89
                //
 
90
                flags=get_bits(&s,6);
 
91
                *flagso=flags;
 
92
                index=get_bits(&s,4); 
 
93
                *fq=dts_sample_rates[index];
 
94
                index=get_bits(&s,5); 
 
95
                *br=dts_bit_rates[index];
 
96
#if 0
 
97
                printf("[dts]Flags  :%u\n",flags);
 
98
                printf("[dts]Fq  :%u\n",*fq);
 
99
                printf("[dts]br  :%u\n",*br);
 
100
                printf("[dts]len1  :%u\n",len1);
 
101
                printf("[dts]len2  :%u\n",len2);
 
102
#endif
 
103
                *syncoff=cur-buf;
 
104
                if(*syncoff) printf("[dts] Dropped %u bytes\n",*syncoff);
 
105
                *chan=dts_channels[flags & 0xf];
 
106
//                if(*chan==5 && (flags & 0X80)) *chan++;
 
107
                *nbSample=nbBlocks*32;
 
108
                return framesize;
 
109
                
 
110
                
 
111
            }
 
112
            printf("[DTS] Cannot find sync\n");
 
113
              return 0;
 
114
}