Subversion Repositories Kolibri OS

Rev

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

Rev 6136 Rev 6144
Line 158... Line 158...
158
    default: break;
158
    default: break;
159
    }
159
    }
160
    return "";
160
    return "";
161
}
161
}
Line 162... Line -...
162
 
-
 
163
VADisplay va_open_display(void)
-
 
164
{
-
 
165
    VADisplay va_dpy;
-
 
166
 
-
 
167
    drm_fd = get_service("DISPLAY");
-
 
168
    if (drm_fd == 0)
-
 
169
        return NULL;
-
 
170
 
-
 
171
    va_dpy = vaGetDisplayDRM(drm_fd);
-
 
172
    if (va_dpy)
-
 
173
        return va_dpy;
-
 
174
 
-
 
175
    drm_fd = 0;
-
 
176
    return NULL;
-
 
Line 177... Line 162...
177
};
162
 
178
 
163
 
179
void *vaapi_init(VADisplay display)
164
void *vaapi_init(VADisplay display)
180
{
165
{
Line 341... Line 326...
341
        return -1;
326
        return -1;
342
    }
327
    }
Line 343... Line 328...
343
 
328
 
344
    printf("vaCreateSurfaces %dx%d\n",picture_width,picture_height);
329
    printf("vaCreateSurfaces %dx%d\n",picture_width,picture_height);
345
    status = vaCreateSurfaces(vaapi->display, VA_RT_FORMAT_YUV420, picture_width, picture_height,
330
    status = vaCreateSurfaces(vaapi->display, VA_RT_FORMAT_YUV420, picture_width, picture_height,
346
                              v_surface_id,vst->nframes,NULL,0);
331
                              v_surface_id,vst->decoder->nframes,NULL,0);
347
    if (!vaapi_check_status(status, "vaCreateSurfaces()"))
332
    if (!vaapi_check_status(status, "vaCreateSurfaces()"))
348
    {
333
    {
349
        FAIL();
334
        FAIL();
350
        return -1;
335
        return -1;
Line 376... Line 361...
376
 
361
 
377
    printf("vaCreateContext %dx%d\n",picture_width,picture_height);
362
    printf("vaCreateContext %dx%d\n",picture_width,picture_height);
378
    status = vaCreateContext(vaapi->display, config_id,
363
    status = vaCreateContext(vaapi->display, config_id,
379
                             picture_width, picture_height,
364
                             picture_width, picture_height,
380
                             VA_PROGRESSIVE,
365
                             VA_PROGRESSIVE,
381
                             v_surface_id, vst->nframes,
366
                             v_surface_id, vst->decoder->nframes,
382
                             &context_id);
367
                             &context_id);
383
    if (!vaapi_check_status(status, "vaCreateContext()"))
368
    if (!vaapi_check_status(status, "vaCreateContext()"))
384
    {
369
    {
385
        FAIL();
370
        FAIL();
Line 397... Line 382...
397
                                   const enum AVPixelFormat *fmt)
382
                                   const enum AVPixelFormat *fmt)
398
{
383
{
399
    vst_t *vst = (vst_t*)avctx->opaque;
384
    vst_t *vst = (vst_t*)avctx->opaque;
400
    VAProfile profile = VAProfileNone;
385
    VAProfile profile = VAProfileNone;
Line 401... Line 386...
401
 
386
 
402
 
387
ENTER();
403
    for (int i = 0; fmt[i] != PIX_FMT_NONE; i++)
388
    for (int i = 0; fmt[i] != PIX_FMT_NONE; i++)
404
    {
389
    {
Line 405... Line 390...
405
        enum AVCodecID codec = avctx->codec_id;
390
        enum AVCodecID codec = avctx->codec_id;
Line 447... Line 432...
447
static int get_buffer2(AVCodecContext *avctx, AVFrame *pic, int flags)
432
static int get_buffer2(AVCodecContext *avctx, AVFrame *pic, int flags)
448
{
433
{
449
    vst_t *vst = (vst_t*)avctx->opaque;
434
    vst_t *vst = (vst_t*)avctx->opaque;
450
    void *surface;
435
    void *surface;
Line 451... Line 436...
451
 
436
 
Line 452... Line 437...
452
    surface = (void *)(uintptr_t)v_surface_id[vst->decoder_frame->index];
437
    surface = (void *)(uintptr_t)v_surface_id[vst->decoder->active_frame->index];
Line 453... Line 438...
453
 
438
 
454
    pic->data[3] = surface;
439
    pic->data[3] = surface;
Line 464... Line 449...
464
    return 0;
449
    return 0;
465
}
450
}
Line 466... Line 451...
466
 
451
 
Line 467... Line -...
467
struct vaapi_context va_context_storage;
-
 
468
 
-
 
469
int fplay_init_context(vst_t *vst)
-
 
470
{
-
 
471
    AVCodecContext *vCtx = vst->vCtx;
-
 
472
 
-
 
473
    vst->nframes = 4;
-
 
474
 
-
 
475
    if(va_check_codec_support(vCtx->codec_id))
-
 
476
    {
-
 
477
        VADisplay dpy;
-
 
478
 
-
 
479
        dpy = va_open_display();
-
 
480
        vst->hwCtx = vaapi_init(dpy);
-
 
481
 
-
 
482
        if(vst->hwCtx != NULL)
-
 
483
        {
-
 
484
            if(vCtx->codec_id == AV_CODEC_ID_H264)
-
 
485
                vst->nframes = 16;
-
 
486
 
-
 
487
            for(int i = 0; i < vst->nframes; i++)
-
 
488
            {
-
 
489
                vframe_t *vframe = &vst->vframes[i];
-
 
490
 
-
 
491
                vframe->format    = AV_PIX_FMT_NONE;
-
 
492
                vframe->is_hw_pic = 1;
-
 
493
                vframe->index     = i;
-
 
494
                vframe->pts       = 0;
-
 
495
                vframe->ready     = 0;
-
 
496
                list_add_tail(&vframe->list, &vst->input_list);
-
 
497
            };
-
 
498
 
-
 
499
            vst->hwdec         = 1;
-
 
500
            vst->frame_reorder = 1;
-
 
501
            vCtx->opaque       = vst;
-
 
502
            vCtx->thread_count = 1;
-
 
503
            vCtx->get_format   = get_format;
-
 
504
            vCtx->get_buffer2  = get_buffer2;
-
 
505
            return 0;
-
 
506
        };
-
 
507
    };
-
 
508
 
-
 
509
    vst->hwdec = 0;
-
 
510
 
-
 
511
    for(int i = 0; i < vst->nframes; i++)
-
 
512
    {
-
 
513
        vframe_t *vframe;
-
 
514
        int ret;
-
 
515
 
-
 
516
        vframe = &vst->vframes[i];
-
 
517
 
-
 
518
        ret = avpicture_alloc(&vframe->picture, vst->vCtx->pix_fmt,
-
 
519
                               vst->vCtx->width, vst->vCtx->height);
-
 
520
        if ( ret != 0 )
-
 
521
        {
-
 
522
            printf("Cannot alloc video buffer\n\r");
-
 
523
            return ret;
-
 
524
        };
-
 
525
        vframe->format = vst->vCtx->pix_fmt;
-
 
526
        vframe->index  = i;
-
 
527
        vframe->pts    = 0;
-
 
528
        vframe->ready  = 0;
-
 
529
        list_add_tail(&vframe->list, &vst->input_list);
-
 
530
    };
-
 
531
 
-
 
Line 532... Line 452...
532
    return 0;
452
struct vaapi_context va_context_storage;
533
}
453
 
534
 
454
 
Line 646... Line 566...
646
                            vaimage.offsets[0],vaimage.pitches[0],
566
                            vaimage.offsets[0],vaimage.pitches[0],
647
                            vaimage.offsets[1],vaimage.pitches[1],
567
                            vaimage.offsets[1],vaimage.pitches[1],
648
                            vaimage.offsets[2],vaimage.pitches[2]);
568
                            vaimage.offsets[2],vaimage.pitches[2]);
649
    if(planar != NULL)
569
    if(planar != NULL)
650
    {
570
    {
651
        printf("create planar image\n",planar);
-
 
652
        vframe->planar = planar;
571
        vframe->planar = planar;
653
        vframe->format = AV_PIX_FMT_NV12;
572
        vframe->format = AV_PIX_FMT_NV12;
654
    };
573
    };
Line 655... Line 574...
655
 
574
 
656
    vaReleaseBufferHandle(vaapi->display, vaimage.buf);
575
    vaReleaseBufferHandle(vaapi->display, vaimage.buf);
Line 657... Line 576...
657
    vaDestroyImage(vaapi->display, vaimage.image_id);
576
    vaDestroyImage(vaapi->display, vaimage.image_id);
-
 
577
 
-
 
578
}
-
 
579
 
-
 
580
struct decoder* va_init_decoder(vst_t *vst)
-
 
581
{
-
 
582
    AVCodecContext *vCtx = vst->vCtx;
-
 
583
    struct decoder *decoder;
-
 
584
    VADisplay dpy;
-
 
585
 
-
 
586
    drm_fd = get_service("DISPLAY");
-
 
587
    if (drm_fd == 0)
-
 
588
        return NULL;
-
 
589
 
-
 
590
    dpy = vaGetDisplayDRM(drm_fd);
-
 
591
    if (dpy == NULL)
-
 
592
        goto err_0;
-
 
593
 
-
 
594
    decoder = calloc(1, sizeof(struct decoder));
-
 
595
    if(decoder == NULL)
-
 
596
        goto err_0;
-
 
597
 
-
 
598
    decoder->hwctx = vaapi_init(dpy);
-
 
599
    if(decoder->hwctx == NULL)
-
 
600
        goto err_1;
-
 
601
 
-
 
602
    decoder->Frame = av_frame_alloc();
-
 
603
    if(decoder->Frame == NULL)
-
 
604
        goto err_1;
-
 
605
 
-
 
606
    if(vCtx->codec_id == AV_CODEC_ID_H264)
-
 
607
        decoder->nframes = 16;
-
 
608
    else
-
 
609
        decoder->nframes = 4;
-
 
610
 
-
 
611
    for(int i = 0; i < decoder->nframes; i++)
-
 
612
    {
-
 
613
        vframe_t *vframe = &decoder->vframes[i];
-
 
614
 
-
 
615
        vframe->format    = AV_PIX_FMT_NONE;
-
 
616
        vframe->is_hw_pic = 1;
-
 
617
        vframe->index     = i;
-
 
618
        vframe->pts       = 0;
-
 
619
        vframe->ready     = 0;
-
 
620
        list_add_tail(&vframe->list, &vst->input_list);
-
 
621
    };
-
 
622
 
-
 
623
    vCtx->opaque       = vst;
-
 
624
    vCtx->thread_count = 1;
-
 
625
    vCtx->get_format   = get_format;
-
 
626
    vCtx->get_buffer2  = get_buffer2;
-
 
627
 
-
 
628
    if(avcodec_open2(vst->vCtx, vst->vCodec, NULL) < 0)
-
 
629
    {
-
 
630
        printf("Error while opening codec for input stream %d\n",
-
 
631
                vst->vStream);
-
 
632
        goto err_2;
-
 
633
    };
-
 
634
 
-
 
635
    decoder->name     = vst->vCodec->name;
-
 
636
    decoder->codec_id = vCtx->codec_id;
-
 
637
    decoder->pix_fmt  = vCtx->pix_fmt;
-
 
638
    decoder->width    = vCtx->width;
-
 
639
    decoder->height   = vCtx->height;
-
 
640
    decoder->is_hw    = 1;
-
 
641
    decoder->frame_reorder = 1;
-
 
642
 
-
 
643
    return decoder;
-
 
644
 
-
 
645
err_2:
-
 
646
    av_frame_free(&decoder->Frame);
-
 
647
err_1:
-
 
648
    free(decoder);
-
 
649
    vaTerminate(dpy);
-
 
650
err_0:
-
 
651
    drm_fd = 0;