Subversion Repositories Kolibri OS

Rev

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

Rev 6136 Rev 6144
Line 20... Line 20...
20
volatile enum player_state sound_state   = STOP;
20
volatile enum player_state sound_state   = STOP;
21
 
21
 
Line 22... Line 22...
22
uint32_t win_width, win_height;
22
uint32_t win_width, win_height;
Line 23... Line -...
23
 
-
 
24
int have_sound = 0;
-
 
25
 
23
 
26
uint8_t  *decoder_buffer;
24
uint8_t  *decoder_buffer;
27
extern int resampler_size;
25
extern int resampler_size;
Line 28... Line 26...
28
extern int sample_rate;
26
extern int sample_rate;
Line 29... Line 27...
29
 
27
 
Line 30... Line 28...
30
int64_t  rewind_pos;
28
int64_t  rewind_pos;
Line 31... Line -...
31
 
-
 
32
int64_t stream_duration;
-
 
Line 33... Line 29...
33
 
29
 
34
int threads_running = DECODER_THREAD;
30
int64_t stream_duration;
35
 
31
 
36
extern double audio_base;
32
int threads_running = DECODER_THREAD;
Line 68... Line 64...
68
    };
64
    };
69
 
65
 
Line 70... Line 66...
70
    vst.fCtx->flags |= AVFMT_FLAG_GENPTS;
66
    vst.fCtx->flags |= AVFMT_FLAG_GENPTS;
Line 71... Line -...
71
 
-
 
72
  // Retrieve stream information
67
 
73
    if(avformat_find_stream_info(vst.fCtx, NULL) < 0)
68
    if(avformat_find_stream_info(vst.fCtx, NULL) < 0)
74
    {
69
    {
75
        printf("Cannot find streams\n\r");
70
        printf("Cannot find streams\n\r");
76
        return -1;
71
        return -1;
Line 87... Line 82...
87
    else vst.input_name = file_name;
82
    else vst.input_name = file_name;
88
 
83
 
Line 89... Line 84...
89
    stream_duration = vst.fCtx->duration;
84
    stream_duration = vst.fCtx->duration;
Line 90... Line -...
90
 
-
 
91
   // Find the first video stream
85
 
92
    vst.vStream = -1;
86
    vst.vStream = -1;
Line 93... Line 87...
93
    vst.aStream = -1;
87
    vst.aStream = -1;
94
 
88
 
Line 106... Line 100...
106
        if(vst.fCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO &&
100
        if(vst.fCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO &&
107
           vst.aStream < 0)
101
           vst.aStream < 0)
108
        {
102
        {
109
            vst.aStream = i;
103
            vst.aStream = i;
110
            vst.audio_time_base = vst.fCtx->streams[i]->time_base;
-
 
111
            if(stream_duration == 0)
104
            if(stream_duration == 0)
112
               stream_duration = vst.fCtx->streams[i]->duration;
105
               stream_duration = vst.fCtx->streams[i]->duration;
113
        }
106
        }
114
    }
107
    }
Line 120... Line 113...
120
    };
113
    };
121
 
114
 
Line 122... Line 115...
122
  //   __asm__ __volatile__("int3");
115
  //   __asm__ __volatile__("int3");
Line 123... Line -...
123
 
-
 
124
    // Get a pointer to the codec context for the video stream
-
 
125
    vst.vCtx = vst.fCtx->streams[vst.vStream]->codec;
-
 
126
    vst.aCtx = vst.fCtx->streams[vst.aStream]->codec;
-
 
127
 
-
 
128
    vst.vCodec = avcodec_find_decoder(vst.vCtx->codec_id);
-
 
129
 
116
 
130
    INIT_LIST_HEAD(&vst.input_list);
117
    INIT_LIST_HEAD(&vst.input_list);
131
    INIT_LIST_HEAD(&vst.output_list);
118
    INIT_LIST_HEAD(&vst.output_list);
132
    mutex_init(&vst.q_video.lock);
119
    mutex_init(&vst.q_video.lock);
133
    mutex_init(&vst.q_audio.lock);
120
    mutex_init(&vst.q_audio.lock);
134
    mutex_init(&vst.gpu_lock);
121
    mutex_init(&vst.gpu_lock);
135
    mutex_init(&vst.decoder_lock);
122
    mutex_init(&vst.decoder_lock);
136
    mutex_init(&vst.input_lock);
123
    mutex_init(&vst.input_lock);
Line 137... Line -...
137
    mutex_init(&vst.output_lock);
-
 
138
 
-
 
139
    if(vst.vCodec == NULL)
-
 
140
    {
124
    mutex_init(&vst.output_lock);
141
        printf("Unsupported codec with id %d for input stream %d\n",
-
 
142
        vst.vCtx->codec_id, vst.vStream);
-
 
143
        return -1;
-
 
144
    }
125
 
145
 
-
 
146
    vst.Frame = av_frame_alloc();
-
 
147
    if(vst.Frame == NULL)
-
 
148
    {
-
 
149
        printf("Cannot alloc video frame\n");
-
 
Line 150... Line 126...
150
        return -1;
126
    vst.vCtx = vst.fCtx->streams[vst.vStream]->codec;
151
    };
127
    vst.aCtx = vst.fCtx->streams[vst.aStream]->codec;
Line 152... Line -...
152
 
-
 
153
    if(fplay_init_context(&vst))
-
 
154
        return -1;
-
 
155
 
-
 
156
    if(avcodec_open2(vst.vCtx, vst.vCodec, NULL) < 0)
-
 
157
    {
-
 
158
        printf("Error while opening codec for input stream %d\n",
-
 
159
                vst.vStream);
-
 
160
        return -1; // Could not open codec
128
 
161
    };
-
 
162
 
-
 
163
    if (vst.aCtx->channels > 0)
-
 
164
        vst.aCtx->request_channels = FFMIN(2, vst.aCtx->channels);
129
    if(init_video_decoder(&vst) != 0 )
165
    else
-
 
166
        vst.aCtx->request_channels = 2;
130
        return -1;
167
 
131
 
168
    vst.aCodec = avcodec_find_decoder(vst.aCtx->codec_id);
132
    vst.aCtx->request_channel_layout = AV_CH_LAYOUT_STEREO;
169
 
133
    vst.aCodec = avcodec_find_decoder(vst.aCtx->codec_id);
170
    if(vst.aCodec)
134
    if(vst.aCodec)
Line 196... Line 160...
196
                    mutex_init(&astream.lock);
160
                    mutex_init(&astream.lock);
197
                    astream.count  = 0;
161
                    astream.count  = 0;
198
                    astream.buffer = (char *)av_mallocz(192000*3);
162
                    astream.buffer = (char *)av_mallocz(192000*3);
199
                    if( astream.buffer != NULL )
163
                    if( astream.buffer != NULL )
200
                        have_sound = 1;
164
                        vst.has_sound = 1;
201
                    else
165
                    else
202
                        av_free(decoder_buffer);
166
                        av_free(decoder_buffer);
203
                }
167
                }
204
                if( have_sound == 0)
168
                if( vst.has_sound == 0)
205
                {
169
                {
206
                        printf("Not enough memory for audio buffers\n");
170
                        printf("Not enough memory for audio buffers\n");
207
                }
171
                }
208
            }
172
            }
209
        }
173
        }
210
        else printf("Cannot open audio codec\n\r");
174
        else printf("Cannot open audio codec\n\r");
Line 227... Line 191...
227
 
191
 
Line 228... Line 192...
228
    if(astream.lock.handle)
192
    if(astream.lock.handle)
229
        mutex_destroy(&astream.lock);
193
        mutex_destroy(&astream.lock);
Line -... Line 194...
-
 
194
 
230
 
195
    fini_video_decoder(&vst);
231
    mutex_destroy(&vst.q_video.lock);
196
    mutex_destroy(&vst.q_video.lock);
232
    mutex_destroy(&vst.q_audio.lock);
197
    mutex_destroy(&vst.q_audio.lock);
-
 
198
    mutex_destroy(&vst.decoder_lock);
233
    mutex_destroy(&vst.decoder_lock);
199
 
234
    return 0;
200
    return 0;
Line 235... Line 201...
235
}
201
}
Line 245... Line 211...
245
    {
211
    {
246
        if(packet.stream_index == vst->vStream)
212
        if(packet.stream_index == vst->vStream)
247
            put_packet(&vst->q_video, &packet);
213
            put_packet(&vst->q_video, &packet);
248
        else if( (packet.stream_index == vst->aStream) &&
214
        else if( (packet.stream_index == vst->aStream) &&
249
                  (have_sound != 0) )
215
                  (vst->has_sound != 0) )
250
        {
216
        {
251
            put_packet(&vst->q_audio, &packet);
217
            put_packet(&vst->q_audio, &packet);
252
            if(audio_base == -1.0)
218
            if(vst->audio_timer_valid == 0 &&
253
            {
219
               packet.pts != AV_NOPTS_VALUE )
-
 
220
            {
254
                if (packet.pts != AV_NOPTS_VALUE)
221
                vst->audio_timer_base = get_audio_base(vst) * packet.pts;
255
                    audio_base = get_audio_base(vst) * packet.pts;
-
 
256
//                    printf("audio base %f\n", audio_base);
222
                vst->audio_timer_valid = 1;
257
            };
223
            };
258
        }
224
        }
259
        else av_free_packet(&packet);
225
        else av_free_packet(&packet);
260
    }
226
    }
261
    else if (err != AVERROR_EOF)
227
    else if (err != AVERROR_EOF)
262
        printf("av_read_frame: error %x\n", err);
228
        printf("av_read_frame: error %x\n", err);