Subversion Repositories Kolibri OS

Rev

Rev 6144 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6144 Rev 6658
Line 12... Line 12...
12
#include "winlib/winlib.h"
12
#include "winlib/winlib.h"
Line 13... Line 13...
13
 
13
 
14
#include "sound.h"
14
#include "sound.h"
Line -... Line 15...
-
 
15
#include "fplay.h"
-
 
16
 
-
 
17
static struct decoder ffmpeg_decoder;
-
 
18
static struct decoder* init_ffmpeg_decoder(vst_t *vst);
-
 
19
 
-
 
20
static decoder_init_fn* decoders[] = {
-
 
21
    init_va_decoder,
-
 
22
    init_ffmpeg_decoder,
-
 
23
    NULL
-
 
24
};
-
 
25
 
-
 
26
static void fini_ffmpeg_decoder(vst_t *vst)
-
 
27
{
-
 
28
    av_frame_free(&vst->decoder->Frame);
-
 
29
 
-
 
30
    for(int i = 0; i < vst->decoder->nframes; i++)
-
 
31
    {
-
 
32
        vframe_t *vframe;
-
 
33
        vframe = &vst->decoder->vframes[i];
-
 
34
        avpicture_free(&vframe->picture);
-
 
35
    };
15
#include "fplay.h"
36
};
16
 
37
 
17
static struct decoder* init_ffmpeg_decoder(vst_t *vst)
38
static struct decoder* init_ffmpeg_decoder(vst_t *vst)
18
{
39
{
19
    AVCodecContext *vCtx = vst->vCtx;
40
    AVCodecContext *vCtx = vst->vCtx;
20
    struct decoder *decoder;
41
    struct decoder *decoder;
Line 21... Line 42...
21
    vframe_t *vframe;
42
    vframe_t *vframe;
22
    int i, ret;
-
 
23
 
-
 
Line 24... Line 43...
24
    decoder = calloc(1, sizeof(struct decoder));
43
    int i, ret;
25
    if(decoder == NULL)
44
 
26
        return NULL;
45
    decoder = &ffmpeg_decoder;
Line 40... Line 59...
40
        if ( ret != 0 )
59
        if ( ret != 0 )
41
            goto err_1;
60
            goto err_1;
Line 42... Line 61...
42
 
61
 
43
        vframe->format = vCtx->pix_fmt;
62
        vframe->format = vCtx->pix_fmt;
44
        vframe->index  = i;
-
 
45
        vframe->pts    = 0;
-
 
46
        vframe->ready  = 0;
63
        vframe->index  = i;
47
        list_add_tail(&vframe->list, &vst->input_list);
64
        list_add_tail(&vframe->list, &vst->input_list);
Line 48... Line 65...
48
    };
65
    };
49
 
66
 
Line 57... Line 74...
57
    decoder->name     = vst->vCodec->name;
74
    decoder->name     = vst->vCodec->name;
58
    decoder->pix_fmt  = vCtx->pix_fmt;
75
    decoder->pix_fmt  = vCtx->pix_fmt;
59
    decoder->width    = vCtx->width;
76
    decoder->width    = vCtx->width;
60
    decoder->height   = vCtx->height;
77
    decoder->height   = vCtx->height;
61
    decoder->codec_id = vCtx->codec_id;
78
    decoder->codec_id = vCtx->codec_id;
62
 
-
 
-
 
79
    decoder->profile  = vCtx->profile;
-
 
80
    decoder->fini     = fini_ffmpeg_decoder;
63
    return decoder;
81
    return decoder;
Line 64... Line 82...
64
 
82
 
65
err_1:
83
err_1:
66
    for(i = i-1; i >= 0; i--)
84
    for(i = i-1; i >= 0; i--)
67
    {
85
    {
68
        vframe = &decoder->vframes[i];
86
        vframe = &decoder->vframes[i];
69
        avpicture_free(&vframe->picture);
87
        avpicture_free(&vframe->picture);
70
    };
-
 
71
    av_frame_free(&decoder->Frame);
88
    };
72
err_0:
-
 
73
    free(decoder);
89
err_0:
74
    return NULL;
90
    return NULL;
Line 75... Line -...
75
}
-
 
76
 
-
 
77
int init_video_decoder(vst_t *vst)
-
 
78
{
-
 
79
    AVCodecContext *vCtx = vst->vCtx;
-
 
80
 
-
 
81
    vst->vCodec = avcodec_find_decoder(vCtx->codec_id);
-
 
82
 
-
 
83
    if(vst->vCodec == NULL)
-
 
84
    {
-
 
85
        printf("Unsupported codec with id %d for input stream %d\n",
-
 
86
        vst->vCtx->codec_id, vst->vStream);
-
 
87
        return -1;
-
 
88
    }
-
 
89
 
-
 
90
    vst->decoder = va_init_decoder(vst);
-
 
91
    if(vst->decoder == NULL)
-
 
92
        vst->decoder = init_ffmpeg_decoder(vst);
-
 
93
 
-
 
94
    if(vst->decoder != NULL)
-
 
95
    {
-
 
96
        printf("%dx%d %s %s%s decoder\n",
-
 
97
                vst->decoder->width, vst->decoder->height,
-
 
98
                av_get_pix_fmt_name(vst->decoder->pix_fmt),
-
 
99
                vst->decoder->is_hw == 0 ? "ffmpeg ":"vaapi ",
-
 
100
                vst->decoder->name);
-
 
101
 
-
 
102
        return 0;
-
 
103
    };
-
 
104
 
-
 
105
    return -1;
-
 
106
}
-
 
107
 
-
 
108
void fini_video_decoder(vst_t *vst)
-
 
109
{
-
 
110
    avcodec_close(vst->vCtx);
-
 
111
 
-
 
112
    if(vst->decoder->is_hw != 0)
-
 
113
        return;
-
 
114
 
-
 
115
    for(int i = 0; i < vst->decoder->nframes; i++)
-
 
116
    {
-
 
117
        vframe_t *vframe;
-
 
118
        vframe = &vst->decoder->vframes[i];
-
 
119
        avpicture_free(&vframe->picture);
-
 
120
    };
-
 
121
    av_frame_free(&vst->decoder->Frame);
-
 
122
    free(vst->decoder);
-
 
123
};
91
}
124
 
92
 
125
static vframe_t *get_input_frame(vst_t *vst)
93
static vframe_t *get_input_frame(vst_t *vst)
Line 126... Line 94...
126
{
94
{
Line 228... Line 196...
228
    av_free_packet(&pkt);
196
    av_free_packet(&pkt);
Line 229... Line 197...
229
 
197
 
230
    return 1;
198
    return 1;
Line -... Line 199...
-
 
199
}
-
 
200
 
-
 
201
int init_video_decoder(vst_t *vst)
-
 
202
{
-
 
203
    decoder_init_fn **init_fn;
-
 
204
    AVCodecContext *vCtx = vst->vCtx;
-
 
205
    int i;
-
 
206
 
-
 
207
    vst->vCodec = avcodec_find_decoder(vCtx->codec_id);
-
 
208
 
-
 
209
    if(vst->vCodec == NULL)
-
 
210
    {
-
 
211
        printf("Unsupported codec with id %d for input stream %d\n",
-
 
212
        vst->vCtx->codec_id, vst->vStream);
-
 
213
        return -1;
-
 
214
    }
-
 
215
 
-
 
216
    for(init_fn = decoders; init_fn != NULL; init_fn++)
-
 
217
    {
-
 
218
        vst->decoder = (*init_fn)(vst);
-
 
219
        if(vst->decoder != NULL)
-
 
220
        {
-
 
221
            printf("%dx%d %s %s%s decoder\n",
-
 
222
                    vst->decoder->width, vst->decoder->height,
-
 
223
                    av_get_pix_fmt_name(vst->decoder->pix_fmt),
-
 
224
                    vst->decoder->is_hw == 0 ? "ffmpeg ":"vaapi ",
-
 
225
                    vst->decoder->name);
-
 
226
 
-
 
227
            return 0;
-
 
228
        };
-
 
229
    }
-
 
230
 
-
 
231
    return -1;