Subversion Repositories Kolibri OS

Rev

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

Rev 6118 Rev 6121
Line 9... Line 9...
9
 
9
 
Line 10... Line 10...
10
#include "winlib/winlib.h"
10
#include "winlib/winlib.h"
11
#include "fplay.h"
11
#include "fplay.h"
Line 12... Line -...
12
 
-
 
13
int fplay_blit_bitmap(bitmap_t *bitmap, int dst_x, int dst_y,int w, int h);
-
 
14
 
12
 
15
extern int res_pause_btn[];
13
extern int res_pause_btn[];
Line 16... Line 14...
16
extern int res_pause_btn_pressed[];
14
extern int res_pause_btn_pressed[];
17
 
15
 
Line 18... Line 16...
18
extern int res_play_btn[];
16
extern int res_play_btn[];
19
extern int res_play_btn_pressed[];
17
extern int res_play_btn_pressed[];
20
 
18
 
Line 21... Line -...
21
extern int64_t stream_duration;
-
 
22
extern volatile int sound_level_0;
-
 
23
extern volatile int sound_level_1;
-
 
24
 
-
 
25
typedef struct
-
 
26
{
-
 
27
    AVPicture      picture;
-
 
28
    double         pts;
-
 
29
    volatile int   ready;
19
extern int64_t stream_duration;
Line 30... Line 20...
30
}vframe_t;
20
extern volatile int sound_level_0;
Line 50... Line 40...
50
    int i;
40
    int i;
51
 
41
 
Line 52... Line 42...
52
    for(i = 0; i < 4; i++)
42
    for(i = 0; i < 4; i++)
53
    {
43
    {
54
        frames[i].pts    = 0;
44
        vst->vframe[i].pts   = 0;
55
        frames[i].ready  = 0;
45
        vst->vframe[i].ready = 0;
56
    };
46
    };
57
    vst->vfx = 0;
47
    vst->vfx = 0;
58
    vst->dfx = 0;
48
    vst->dfx = 0;
59
    frames_count = 0;
49
    frames_count = 0;
60
};
50
};
Line 72... Line 62...
72
        printf("Cannot alloc video frame\n\r");
62
        printf("Cannot alloc video frame\n\r");
73
        return 0;
63
        return 0;
74
    };
64
    };
75
 
65
 
Line 76... Line -...
76
    for( i=0; i < 4; i++)
-
 
77
    {
-
 
78
        int ret;
-
 
79
 
-
 
80
        ret = avpicture_alloc(&frames[i].picture, vst->vCtx->pix_fmt,
-
 
81
                               vst->vCtx->width, vst->vCtx->height);
-
 
82
        if ( ret != 0 )
-
 
83
        {
-
 
84
            printf("Cannot alloc video buffer\n\r");
-
 
85
            return 0;
-
 
86
        };
-
 
87
 
-
 
88
        frames[i].pts    = 0;
-
 
89
        frames[i].ready  = 0;
-
 
90
    };
-
 
91
 
-
 
92
    create_thread(video_thread, vst, 1024*1024);
66
    create_thread(video_thread, vst, 1024*1024);
Line 93... Line 67...
93
 
67
 
94
    delay(50);
68
    delay(50);
95
    return 1;
69
    return 1;
Line 101... Line 75...
101
    double     pts;
75
    double     pts;
102
    int frameFinished;
76
    int frameFinished;
103
    double current_clock;
77
    double current_clock;
104
 
78
 
Line 105... Line 79...
105
    if(frames[vst->dfx].ready != 0 )
79
    if(vst->vframe[vst->dfx].ready != 0 )
106
        return -1;
80
        return -1;
Line 107... Line 81...
107
 
81
 
108
    if( get_packet(&vst->q_video, &pkt) == 0 )
82
    if( get_packet(&vst->q_video, &pkt) == 0 )
Line 146... Line 120...
146
                pts = 0;
120
                pts = 0;
147
 
121
 
Line 148... Line 122...
148
            pts *= av_q2d(video_time_base);
122
            pts *= av_q2d(video_time_base);
Line 149... Line 123...
149
 
123
 
Line -... Line 124...
-
 
124
            dst_pic = &vst->vframe[vst->dfx].picture;
150
            dst_pic = &frames[vst->dfx].picture;
125
 
151
 
126
            if(vst->hwdec == 0)
152
            av_image_copy(dst_pic->data, dst_pic->linesize,
127
                av_image_copy(dst_pic->data, dst_pic->linesize,
-
 
128
                              (const uint8_t**)Frame->data,
-
 
129
                              Frame->linesize, vst->vCtx->pix_fmt, vst->vCtx->width, vst->vCtx->height);
Line 153... Line 130...
153
                      (const uint8_t**)Frame->data,
130
            else
154
                      Frame->linesize, vst->vCtx->pix_fmt, vst->vCtx->width, vst->vCtx->height);
-
 
155
 
131
                va_convert_picture(vst, vst->vCtx->width, vst->vCtx->height, dst_pic);
156
            frames[vst->dfx].pts = pts*1000.0;
-
 
157
 
132
 
158
            frames[vst->dfx].ready = 1;
133
            vst->vframe[vst->dfx].pts = pts*1000.0;
159
 
134
            vst->vframe[vst->dfx].ready = 1;
160
            vst->dfx = (vst->dfx + 1) & 3;
135
            vst->dfx = (vst->dfx + 1) & 3;
Line 415... Line 390...
415
    };
390
    };
416
 
391
 
Line 417... Line 392...
417
 
392
 
418
#ifdef VERSION_A
393
#ifdef VERSION_A
419
    if(frames[vst->vfx].ready == 1 )
394
    if(vst->vframe[vst->vfx].ready == 1 )
420
    {
395
    {
Line 421... Line 396...
421
        int sys_time;
396
        int sys_time;
422
 
397
 
Line 423... Line 398...
423
        ctime = get_master_clock();
398
        ctime = get_master_clock();
424
        fdelay = (frames[vst->vfx].pts - ctime);
399
        fdelay = (vst->vframe[vst->vfx].pts - ctime);
Line 425... Line 400...
425
 
400
 
Line 432... Line 407...
432
        //    return;
407
        //    return;
433
        };
408
        };
434
#if 0
409
#if 0
435
        ctime = get_master_clock();
410
        ctime = get_master_clock();
436
        fdelay = (frames[vst->vfx].pts - ctime);
411
        fdelay = (vst->vframe[vst->vfx].pts - ctime);
437
 
412
 
Line 438... Line 413...
438
//        while(fdelay > 0)
413
//        while(fdelay > 0)
439
//        {
414
//        {
440
//            yield();
415
//            yield();
441
//            ctime = get_master_clock();
416
//            ctime = get_master_clock();
Line 448... Line 423...
448
//            printf("systime %d pts %f time %f delay %f\n",
423
//            printf("systime %d pts %f time %f delay %f\n",
449
//                    sys_time*10, frames[vfx].pts, ctime, fdelay);
424
//                    sys_time*10, frames[vfx].pts, ctime, fdelay);
450
 
425
 
Line 451... Line 426...
451
        printf("pts %f time %f delay %f\n",
426
        printf("pts %f time %f delay %f\n",
452
                frames[vfx].pts, ctime, fdelay);
427
                vst->vframe[vst->vfx].pts, ctime, fdelay);
453
        printf("video cache %d audio cache %d\n", q_video.size/1024, q_audio.size/1024);
428
        printf("video cache %d audio cache %d\n", q_video.size/1024, q_audio.size/1024);
454
#endif
429
#endif
Line 455... Line 430...
455
 
430
 
456
        main_render->draw(main_render, &frames[vst->vfx].picture);
431
        main_render->draw(main_render, &vst->vframe[vst->vfx].picture);
457
        if(main_render->win->win_state != FULLSCREEN)
432
        if(main_render->win->win_state != FULLSCREEN)
458
        {
433
        {
459
            prg->current = frames[vst->vfx].pts*1000;
434
            prg->current = vst->vframe[vst->vfx].pts*1000;
460
//        printf("current %f\n", prg->current);
435
//        printf("current %f\n", prg->current);
Line 461... Line 436...
461
            lvl->current = vst->vfx & 1 ? sound_level_1 : sound_level_0;
436
            lvl->current = vst->vfx & 1 ? sound_level_1 : sound_level_0;
Line 462... Line 437...
462
 
437
 
463
            send_message(&prg->ctrl, PRG_PROGRESS, 0, 0);
438
            send_message(&prg->ctrl, PRG_PROGRESS, 0, 0);
464
 
439
 
Line 465... Line 440...
465
            if(main_render->win->panel.layout)
440
            if(main_render->win->panel.layout)
466
                send_message(&lvl->ctrl, MSG_PAINT, 0, 0);
441
                send_message(&lvl->ctrl, MSG_PAINT, 0, 0);
467
        }
442
        }
468
 
443
 
469
        frames_count--;
444
        frames_count--;
Line 470... Line 445...
470
        frames[vst->vfx].ready = 0;
445
        vst->vframe[vst->vfx].ready = 0;
Line 471... Line 446...
471
        vst->vfx = (vst->vfx + 1) & 3;
446
        vst->vfx = (vst->vfx + 1) & 3;
472
    }
447
    }
473
    else delay(1);
448
    else delay(1);
474
 
449
 
Line 475... Line 450...
475
#else
450
#else
476
 
451
 
Line 477... Line 452...
477
    if(frames[vfx].ready == 1 )
452
    if(vst->vframe[vfx].ready == 1 )
478
    {
453
    {
479
        ctime = get_master_clock();
454
        ctime = get_master_clock();
480
        fdelay = (frames[vst->vfx].pts - ctime);
455
        fdelay = (vst->vrame[vst->vfx].pts - ctime);
481
 
456
 
482
//            printf("pts %f time %f delay %f\n",
457
//            printf("pts %f time %f delay %f\n",
483
//                    frames[vfx].pts, ctime, fdelay);
458
//                    frames[vfx].pts, ctime, fdelay);
484
 
459
 
485
        if(fdelay < 0.0 )
460
        if(fdelay < 0.0 )
486
        {
461
        {
487
            int  next_vfx;
462
            int  next_vfx;
488
            fdelay = 0;
463
            fdelay = 0;
489
            next_vfx = (vst->vfx+1) & 3;
464
            next_vfx = (vst->vfx+1) & 3;
490
            if( frames[next_vfx].ready == 1 )
465
            if( vst->vrame[next_vfx].ready == 1 )
491
            {
466
            {
492
                if(frames[next_vfx].pts <= ctime)
467
                if(vst->vrame[next_vfx].pts <= ctime)
493
                {
468
                {
494
                    frames[vst->vfx].ready = 0;                  // skip this frame
469
                    vst->vrame[vst->vfx].ready = 0;                  // skip this frame
495
                    vst->vfx = (vst->vfx + 1) & 3;
470
                    vst->vfx = (vst->vfx + 1) & 3;
496
                }
471
                }
497
                else
472
                else
498
                {
473
                {
499
                    if( (frames[next_vfx].pts - ctime) <
474
                    if( (vst->vrame[next_vfx].pts - ctime) <
500
                        ( ctime - frames[vst->vfx].pts) )
475
                        ( ctime - frames[vst->vfx].pts) )
Line 501... Line 476...
501
                    {
476
                    {
502
                        frames[vst->vfx].ready = 0;                  // skip this frame
477
                        vst->vrame[vst->vfx].ready = 0;                  // skip this frame
503
                        vst->vfx = (vst->vfx + 1) & 3;
478
                        vst->vfx = (vst->vfx + 1) & 3;
504
                        fdelay = (frames[next_vfx].pts - ctime);
479
                        fdelay = (vst->vrame[next_vfx].pts - ctime);
505
                    }
480
                    }
506
                }
481
                }
507
            };
482
            };
Line 508... Line 483...
508
        };
483
        };
509
 
484
 
Line 510... Line 485...
510
        if(fdelay > 10.0)
485
        if(fdelay > 10.0)
511
        {
486
        {
Line 512... Line 487...
512
           int val = fdelay;
487
           int val = fdelay;
513
           printf("pts %f time %f delay %d\n",
488
           printf("pts %f time %f delay %d\n",
514
                   frames[vst->vfx].pts, ctime, val);
489
                   vst->vrame[vst->vfx].pts, ctime, val);
515
           delay(val/10);
490
           delay(val/10);
516
        };
491
        };
517
 
492
 
518
        ctime = get_master_clock();
493
        ctime = get_master_clock();
519
        fdelay = (frames[vst->vfx].pts - ctime);
494
        fdelay = (vst->vrame[vst->vfx].pts - ctime);
Line 815... Line 790...
815
    uint8_t  *bitmap_data;
790
    uint8_t  *bitmap_data;
816
    uint32_t  bitmap_pitch;
791
    uint32_t  bitmap_pitch;
817
    uint8_t  *data[4];
792
    uint8_t  *data[4];
818
    int       linesize[4];
793
    int       linesize[4];
819
 
794
    enum AVPixelFormat format;
-
 
795
 
Line 820... Line 796...
820
    if(render->win->win_state == MINIMIZED ||
796
    if(render->win->win_state == MINIMIZED ||
821
       render->win->win_state == ROLLED)
797
       render->win->win_state == ROLLED)
822
        return;
798
        return;
Line 831... Line 807...
831
        dst_width  = render->rcvideo.r;
807
        dst_width  = render->rcvideo.r;
832
        dst_height = render->rcvideo.b;
808
        dst_height = render->rcvideo.b;
833
    };
809
    };
834
 
810
 
Line -... Line 811...
-
 
811
	format = render->vst->hwdec == 0 ? render->ctx_format : AV_PIX_FMT_BGRA
835
    cvt_ctx = sws_getCachedContext(cvt_ctx,
812
    cvt_ctx = sws_getCachedContext(cvt_ctx,
836
              render->ctx_width, render->ctx_height, render->ctx_format,
813
              render->ctx_width, render->ctx_height, format,
837
              dst_width, dst_height, AV_PIX_FMT_BGRA,
814
              dst_width, dst_height, AV_PIX_FMT_BGRA,
838
              SWS_FAST_BILINEAR, NULL, NULL, NULL);
815
              SWS_FAST_BILINEAR, NULL, NULL, NULL);
839
    if(cvt_ctx == NULL)
816
    if(cvt_ctx == NULL)
840
    {
817
    {
841
        printf("Cannot initialize the conversion context!\n");
818
        printf("Cannot initialize the conversion context!\n");
Line 958... Line 935...
958
        y = CAPTION_HEIGHT;
935
        y = CAPTION_HEIGHT;
959
 
936
 
Line 960... Line 937...
960
    if(player_state == PAUSE)
937
    if(player_state == PAUSE)
961
    {
938
    {
962
         if(frames[vst->vfx].ready == 1 )
939
         if(vst->vframe[vst->vfx].ready == 1 )
963
            main_render->draw(main_render, &frames[vst->vfx].picture);
940
            main_render->draw(main_render, &vst->vframe[vst->vfx].picture);
964
         else
941
         else
965
            draw_bar(0, y, render->win_width,
942
            draw_bar(0, y, render->win_width,
966
                 render->rcvideo.b, 0);
943
                 render->rcvideo.b, 0);
967
    }
944
    }
968
    else if( player_state == STOP )
945
    else if( player_state == STOP )