Subversion Repositories Kolibri OS

Rev

Rev 1696 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1696 Rev 2349
Line 12... Line 12...
12
astream_t astream;
12
astream_t astream;
Line 13... Line 13...
13
 
13
 
Line 14... Line 14...
14
static SNDBUF hBuff;
14
static SNDBUF hBuff;
Line 15... Line 15...
15
 
15
 
Line 16... Line 16...
16
extern volatile uint32_t status;
16
extern uint8_t *decoder_buffer;
17
 
-
 
18
void audio_thread(void *param);
-
 
Line 19... Line -...
19
 
-
 
20
void spinlock_lock(volatile uint32_t *val)
-
 
21
{
-
 
22
    uint32_t tmp;
-
 
23
 
-
 
24
    __asm__ __volatile__ (
-
 
25
"0:\n\t"
-
 
26
    "mov %0, %1\n\t"
-
 
27
    "testl %1, %1\n\t"
-
 
28
    "jz 1f\n\t"
-
 
29
 
-
 
30
    "movl $68, %%eax\n\t"
-
 
31
    "movl $1,  %%ebx\n\t"
-
 
32
    "int  $0x40\n\t"
-
 
33
    "jmp 0b\n\t"
-
 
34
"1:\n\t"
-
 
35
    "incl %1\n\t"
-
 
36
    "xchgl %0, %1\n\t"
-
 
Line 37... Line 17...
37
    "testl %1, %1\n\t"
17
 
38
	"jnz 0b\n"
18
extern volatile uint32_t status;
Line 39... Line 19...
39
    : "+m" (*val), "=&r"(tmp)
19
 
40
    ::"eax","ebx" );
20
extern volatile uint32_t driver_lock;
41
}
21
 
42
 
22
 
43
static int snd_format;
23
static int snd_format;
Line -... Line 24...
-
 
24
int sample_rate;
-
 
25
 
44
int sample_rate;
26
int init_audio(int format)
45
 
27
{
-
 
28
    int    err;
46
int init_audio(int format)
29
    int    version =-1;
47
{
30
    char  *errstr;
48
    int    err;
31
 
-
 
32
    mutex_lock(&driver_lock);
-
 
33
 
-
 
34
    if((err = InitSound(&version)) !=0 )
49
    int    version =-1;
35
    {
Line 50... Line 36...
50
    char  *errstr;
36
        mutex_unlock(&driver_lock);
51
 
37
        errstr = "Sound service not installed\n\r";
52
    if((err = InitSound(&version)) !=0 )
38
        goto exit_whith_error;
Line 64... Line 50...
64
    }
50
    }
65
 
51
 
Line 66... Line 52...
66
    snd_format = format;
52
    snd_format = format;
Line 67... Line -...
67
 
-
 
68
    asm volatile ( "xchgw %bx, %bx");
-
 
69
 
53
 
Line 70... Line 54...
70
    create_thread(audio_thread, 0, 163840);
54
    create_thread(audio_thread, 0, 163840);
Line 71... Line 55...
71
 
55
 
Line 87... Line 71...
87
    GetTimeStamp(hBuff, &tstamp);
71
    GetTimeStamp(hBuff, &tstamp);
88
    return tstamp - audio_delta;
72
    return tstamp - audio_delta;
89
};
73
};
Line -... Line 74...
-
 
74
 
-
 
75
int decode_audio(AVCodecContext  *ctx, queue_t *qa)
-
 
76
{
-
 
77
    AVPacket   pkt;
-
 
78
    AVPacket    pkt_tmp;
-
 
79
 
-
 
80
    uint8_t    *audio_data;
-
 
81
    int         audio_size;
-
 
82
    int         len;
-
 
83
    int         data_size=0;
-
 
84
 
-
 
85
    if( astream.count > AVCODEC_MAX_AUDIO_FRAME_SIZE*7)
-
 
86
        return 1;
-
 
87
 
-
 
88
    if( get_packet(qa, &pkt) == 0 )
Line -... Line 89...
-
 
89
        return 0;
-
 
90
 
-
 
91
 //          __asm__("int3");
-
 
92
 
-
 
93
    pkt_tmp = pkt;
-
 
94
 
-
 
95
    while(pkt_tmp.size > 0)
-
 
96
    {
-
 
97
        data_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
-
 
98
 
-
 
99
        len = avcodec_decode_audio3(ctx,(int16_t*)decoder_buffer,
-
 
100
                                   &data_size, &pkt_tmp);
-
 
101
 
-
 
102
        if(len >= 0)
-
 
103
        {
-
 
104
            pkt_tmp.data += len;
-
 
105
            pkt_tmp.size -= len;
-
 
106
 
-
 
107
            mutex_lock(&astream.lock);
-
 
108
            memcpy(astream.buffer+astream.count, decoder_buffer, data_size);
-
 
109
            astream.count += data_size;
-
 
110
            mutex_unlock(&astream.lock);
-
 
111
       }
-
 
112
       else pkt_tmp.size = 0;
-
 
113
    }
-
 
114
    av_free_packet(&pkt);
-
 
115
    return 1;
-
 
116
};
90
 
117
 
91
 
118
 
92
void audio_thread(void *param)
119
int audio_thread(void *param)
93
{
120
{
94
    SND_EVENT evnt;
121
    SND_EVENT evnt;
95
    int       buffsize;
122
    int       buffsize;
Line 119... Line 146...
119
    while( (astream.count < buffsize*2) &&
146
    while( (astream.count < buffsize*2) &&
120
               (status != 0) )
147
               (status != 0) )
121
        yield();
148
        yield();
Line 122... Line 149...
122
 
149
 
123
    spinlock_lock(&astream.lock);
150
    mutex_lock(&astream.lock);
124
    {
151
    {
125
        SetBuffer(hBuff, astream.buffer, 0, buffsize);
152
        SetBuffer(hBuff, astream.buffer, 0, buffsize);
126
        astream.count -= buffsize;
153
        astream.count -= buffsize;
127
        if(astream.count)
154
        if(astream.count)
128
            memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
155
            memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
129
        spinlock_unlock(&astream.lock);
156
        mutex_unlock(&astream.lock);
Line 130... Line 157...
130
    };
157
    };
131
 
158
 
132
    if((err = PlayBuffer(hBuff, 0)) !=0 )
159
    if((err = PlayBuffer(hBuff, 0)) !=0 )
Line 161... Line 188...
161
        samples_lost = audio_delta*sample_rate/1000;
188
        samples_lost = audio_delta*sample_rate/1000;
162
 
189
 
Line 163... Line 190...
163
        offset = evnt.offset;
190
        offset = evnt.offset;
Line 164... Line 191...
164
 
191
 
165
        spinlock_lock(&astream.lock);
192
        mutex_lock(&astream.lock);
166
        {
193
        {
167
            SetBuffer(hBuff, astream.buffer, offset, buffsize);
194
            SetBuffer(hBuff, astream.buffer, offset, buffsize);
168
            astream.count -= buffsize;
195
            astream.count -= buffsize;
169
            if(astream.count)
196
            if(astream.count)
170
                memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
197
                memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
171
            spinlock_unlock(&astream.lock);
198
            mutex_unlock(&astream.lock);
172
        };
199
        };
173
        break;
200
        break;
174
    };
201
    };
Line 219... Line 246...
219
 
246
 
Line 220... Line 247...
220
        if((too_late == 1) || (status == 0))
247
        if((too_late == 1) || (status == 0))
221
            continue;
248
            continue;
Line 222... Line 249...
222
 
249
 
223
        spinlock_lock(&astream.lock);
250
        mutex_lock(&astream.lock);
224
        SetBuffer(hBuff, astream.buffer, offset, buffsize);
251
        SetBuffer(hBuff, astream.buffer, offset, buffsize);
225
        astream.count -= buffsize;
252
        astream.count -= buffsize;
226
        if(astream.count)
253
        if(astream.count)
227
            memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
254
            memcpy(astream.buffer, astream.buffer+buffsize, astream.count);
228
        spinlock_unlock(&astream.lock);
255
        mutex_unlock(&astream.lock);
Line -... Line 256...
-
 
256
    }
-
 
257
 
-
 
258
    StopBuffer(hBuff);
229
    }
259
    DestroyBuffer(hBuff);
Line 230... Line 260...
230
 
260
 
Line 231... Line 261...
231
    return;
261
    return 0;
232
 
262
 
Line 233... Line 263...
233
exit_whith_error:
263
exit_whith_error: