Subversion Repositories Kolibri OS

Rev

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

Rev 2427 Rev 2693
Line 34... Line 34...
34
uint8_t     *decoder_buffer;
34
uint8_t     *decoder_buffer;
35
extern int sample_rate;
35
extern int sample_rate;
36
char *movie_file;
36
char *movie_file;
Line -... Line 37...
-
 
37
 
Line 37... Line 38...
37
 
38
void flush_video();
38
 
39
 
-
 
40
queue_t  q_video;
-
 
41
queue_t  q_audio;
-
 
42
int64_t  rewind_pos;
-
 
43
 
-
 
44
int64_t stream_duration;
-
 
45
 
-
 
46
extern double audio_base;
-
 
47
 
-
 
48
double get_audio_base()
-
 
49
{
-
 
50
 
-
 
51
  return (double)av_q2d(pFormatCtx->streams[audioStream]->time_base)*1000;
-
 
52
 
Line 39... Line 53...
39
queue_t  q_video;
53
};
40
queue_t  q_audio;
54
 
41
 
55
 
Line 62... Line 76...
62
        printf("Cannot open file %s\n\r", argv[1]);
76
        printf("Cannot open file %s\n\r", argv[1]);
63
        return -1; // Couldn't open file
77
        return -1; // Couldn't open file
64
    };
78
    };
65
 
79
 
Line 66... Line 80...
66
//    printf("%s\n\r", __FUNCTION__);
80
    pFormatCtx->flags |= AVFMT_FLAG_GENPTS;
Line 67... Line 81...
67
 
81
 
68
  // Retrieve stream information
82
  // Retrieve stream information
69
    if(avformat_find_stream_info(pFormatCtx, NULL)<0)
83
    if(avformat_find_stream_info(pFormatCtx, NULL)<0)
70
    {
84
    {
Line 75... Line 89...
75
//    __asm__ __volatile__("int3");
89
//    __asm__ __volatile__("int3");
Line 76... Line 90...
76
 
90
 
Line -... Line 91...
-
 
91
//  dump_format(pFormatCtx, 0, argv[1], 0);
-
 
92
 
-
 
93
//    stream_duration = 1000.0 * pFormatCtx->duration * av_q2d(AV_TIME_BASE_Q);
-
 
94
    stream_duration = pFormatCtx->duration;
77
//  dump_format(pFormatCtx, 0, argv[1], 0);
95
    
78
 
96
    printf("duration %f\n", (double)stream_duration);
79
   // Find the first video stream
97
   // Find the first video stream
80
    videoStream=-1;
98
    videoStream=-1;
81
    audioStream=-1;
99
    audioStream=-1;
-
 
100
    for(i=0; i < pFormatCtx->nb_streams; i++)
-
 
101
    {
82
    for(i=0; i < pFormatCtx->nb_streams; i++)
102
//        pFormatCtx->streams[i]->discard = AVDISCARD_ALL;
83
    {
103
 
84
        if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO
104
        if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO
85
            && videoStream < 0)
105
            && videoStream < 0)
86
        {
106
        {
-
 
107
            videoStream=i;
-
 
108
            video_time_base = pFormatCtx->streams[i]->time_base;
-
 
109
            if(stream_duration == 0)
-
 
110
//                stream_duration = 1000.0 *
-
 
111
//                              pFormatCtx->streams[i]->duration *
Line 87... Line 112...
87
            videoStream=i;
112
//                              av_q2d(pFormatCtx->streams[i]->time_base);
88
            video_time_base = pFormatCtx->streams[i]->time_base;
113
               stream_duration = pFormatCtx->streams[i]->duration;
89
 
114
                              
90
        }
115
        }
91
        if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO &&
116
        if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO &&
-
 
117
            audioStream < 0)
-
 
118
        {
-
 
119
            audioStream=i;
-
 
120
            if(stream_duration == 0)
-
 
121
//                stream_duration = 1000.0 *
-
 
122
//                              pFormatCtx->streams[i]->duration *
92
            audioStream < 0)
123
//                              av_q2d(pFormatCtx->streams[i]->time_base);
93
        {
124
               stream_duration = pFormatCtx->streams[i]->duration;
Line 94... Line 125...
94
            audioStream=i;
125
 
95
        }
126
        }
96
    }
127
    }
97
 
128
 
98
    if(videoStream==-1)
129
    if(videoStream==-1)
Line 99... Line 130...
99
    {
130
    {
Line 100... Line 131...
100
        printf("Video stream not detected\n\r");
131
        printf("Video stream not detected\n\r");
Line 101... Line 132...
101
        return -1; // Didn't find a video stream
132
        return -1; // Didn't find a video stream
102
    }
133
    }
Line 198... Line 229...
198
 
229
 
Line 199... Line 230...
199
    return 0;
230
    return 0;
200
}
231
}
Line -... Line 232...
-
 
232
 
201
 
233
 
202
void decoder()
234
static int fill_queue()
203
{
235
{
204
    int       eof = 0;
236
    int eof = 0;
-
 
237
    AVPacket  packet;
-
 
238
 
-
 
239
    while( !eof)
-
 
240
    {
-
 
241
        int err;
-
 
242
 
-
 
243
//        __asm__ __volatile__("int3");
-
 
244
 
-
 
245
        if(q_video.size+q_audio.size < 2*1024*1024)
-
 
246
        {
-
 
247
            err = av_read_frame(pFormatCtx, &packet);
-
 
248
            if( err < 0)
-
 
249
            {
-
 
250
                eof = 1;
-
 
251
                if (err != AVERROR_EOF)
-
 
252
                    printf("av_read_frame: error %x\n", err);
-
 
253
                break;
-
 
254
            }
-
 
255
            if(packet.stream_index==videoStream)
-
 
256
            {
-
 
257
                put_packet(&q_video, &packet);
-
 
258
            }
-
 
259
            else if( (packet.stream_index == audioStream) &&
-
 
260
                 (have_sound != 0) )
-
 
261
            {
-
 
262
                put_packet(&q_audio, &packet);
-
 
263
                if(audio_base == -1.0)
-
 
264
                {
-
 
265
                    if (packet.dts != AV_NOPTS_VALUE)
-
 
266
                        audio_base = get_audio_base() * packet.dts;
-
 
267
//                    printf("audio base %f\n", audio_base);
-
 
268
                };
-
 
269
            }
-
 
270
            else
-
 
271
            {
-
 
272
                av_free_packet(&packet);
-
 
273
            };
-
 
274
        }
-
 
275
        else break;
-
 
276
    };
-
 
277
 
-
 
278
    return eof;
-
 
279
 
-
 
280
};
-
 
281
 
-
 
282
 
-
 
283
void decoder()
-
 
284
{
-
 
285
    int       eof;
205
    AVPacket  packet;
286
    AVPacket  packet;
Line -... Line 287...
-
 
287
    int       ret;
-
 
288
 
206
    int       ret;
289
    eof = fill_queue();
207
 
290
 
208
    while( player_state != CLOSED && !eof)
291
    while( player_state != CLOSED && !eof)
Line 209... Line 292...
209
    {
292
    {
Line 216... Line 299...
216
            delay(1);
299
            delay(1);
217
            continue;
300
            continue;
218
        };
301
        };
219
 
302
 
Line -... Line 303...
-
 
303
        if( player_state == REWIND )
-
 
304
        {
-
 
305
 //           int64_t timestamp = 0;
-
 
306
 //           int stream_index = av_find_default_stream_index(pFormatCtx);
-
 
307
 
-
 
308
 //           __asm__ __volatile__("int3");
-
 
309
 
-
 
310
            if (pFormatCtx->start_time != AV_NOPTS_VALUE)
-
 
311
                rewind_pos += pFormatCtx->start_time;
-
 
312
 
-
 
313
            printf("rewind %8"PRId64"\n", rewind_pos);
-
 
314
            
-
 
315
            ret = avformat_seek_file(pFormatCtx, -1, INT64_MIN,
-
 
316
                                     rewind_pos, INT64_MAX, 0);
-
 
317
//            ret = avformat_seek_file(pFormatCtx, -1, 0,
-
 
318
//                                 0, INT64_MAX, 0);
-
 
319
//            __asm__ __volatile__("int3");
-
 
320
 
-
 
321
            if (ret < 0)
-
 
322
            {
-
 
323
                printf("could not seek to position %f\n",
-
 
324
                        (double)rewind_pos / AV_TIME_BASE);
-
 
325
            }
-
 
326
            else
-
 
327
            {
-
 
328
                avcodec_flush_buffers(pCodecCtx);
-
 
329
                avcodec_flush_buffers(aCodecCtx);
-
 
330
 
-
 
331
                while( get_packet(&q_video, &packet) != 0)
-
 
332
                    av_free_packet(&packet);
-
 
333
 
-
 
334
                while( get_packet(&q_audio, &packet)!= 0)
-
 
335
                    av_free_packet(&packet);
-
 
336
                audio_base = -1.0;
-
 
337
 
-
 
338
  //              __asm__ __volatile__("int3");
-
 
339
 
-
 
340
                eof = fill_queue();
-
 
341
            };
-
 
342
            yield();
-
 
343
 
-
 
344
            flush_video();
-
 
345
 
-
 
346
            player_state = REWIND_2_PLAY;
-
 
347
            printf("restart\n");
-
 
348
            continue;
-
 
349
        };
-
 
350
 
220
        if(q_video.size+q_audio.size < 12*1024*1024)
351
        if(q_video.size+q_audio.size < 4*1024*1024)
221
        {
352
        {
222
            err = av_read_frame(pFormatCtx, &packet);
353
            err = av_read_frame(pFormatCtx, &packet);
223
            if( err < 0)
354
            if( err < 0)
224
            {
355
            {
225
                eof = 1;
356
                eof = 1;