Subversion Repositories Kolibri OS

Rev

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

Rev 6133 Rev 6135
Line 74... Line 74...
74
};
74
};
75
 
75
 
Line 76... Line 76...
76
static double  dts = 0.0;
76
static double  dts = 0.0;
Line 77... Line 77...
77
 
77
 
78
int decode_video(vst_t* vst)
78
static vframe_t *get_input_frame(vst_t *vst)
79
{
-
 
80
    AVPacket   pkt;
-
 
81
    double     pts;
79
{
Line 82... Line -...
82
    int frameFinished;
-
 
83
 
-
 
84
    if(vst->decoder_frame == NULL)
80
    vframe_t *vframe = NULL;
85
    {
81
 
86
        mutex_lock(&vst->input_lock);
82
    mutex_lock(&vst->input_lock);
87
        if(list_empty(&vst->input_list))
83
    if(!list_empty(&vst->input_list))
88
        {
84
    {
89
            mutex_unlock(&vst->input_lock);
85
        vframe = list_first_entry(&vst->input_list, vframe_t, list);
90
            return -1;
-
 
91
        }
-
 
92
        vst->decoder_frame = list_first_entry(&vst->input_list, vframe_t, list);
86
        list_del(&vframe->list);
Line -... Line 87...
-
 
87
    }
-
 
88
    mutex_unlock(&vst->input_lock);
-
 
89
 
-
 
90
    return vframe;
-
 
91
}
-
 
92
 
-
 
93
static void put_output_frame(vst_t *vst, vframe_t *vframe)
93
        list_del(&vst->decoder_frame->list);
94
{
-
 
95
    mutex_lock(&vst->output_lock);
-
 
96
    if(list_empty(&vst->output_list))
-
 
97
        list_add_tail(&vframe->list, &vst->output_list);
-
 
98
    else
-
 
99
    {
-
 
100
        vframe_t *cur;
-
 
101
 
-
 
102
        cur = list_first_entry(&vst->output_list,vframe_t,list);
-
 
103
        if(vframe->pts < cur->pts)
-
 
104
            list_add_tail(&vframe->list, &vst->output_list);
-
 
105
        else
-
 
106
        {
-
 
107
            list_for_each_entry_reverse(cur,&vst->output_list,list)
-
 
108
            {
-
 
109
                if(vframe->pts > cur->pts)
-
 
110
                {
-
 
111
                    list_add(&vframe->list, &cur->list);
-
 
112
                    break;
-
 
113
                };
-
 
114
            };
94
        mutex_unlock(&vst->input_lock);
115
        };
Line 95... Line 116...
95
 
116
    };
96
        vframe_t *vframe = vst->decoder_frame;
117
    mutex_unlock(&vst->output_lock);
-
 
118
};
-
 
119
 
-
 
120
int decode_video(vst_t* vst)
-
 
121
{
-
 
122
    AVPacket   pkt;
-
 
123
    double     pts;
-
 
124
    int frameFinished;
-
 
125
 
-
 
126
    if(vst->decoder_frame == NULL)
-
 
127
        vst->decoder_frame = get_input_frame(vst);
-
 
128
 
97
    };
129
    if(vst->decoder_frame == NULL)
98
 
-
 
Line 99... Line 130...
99
    if( get_packet(&vst->q_video, &pkt) == 0 )
130
        return 0;
100
    {
131
 
101
        return 0;
132
    if( get_packet(&vst->q_video, &pkt) == 0 )
Line 111... Line 142...
111
        printf("video decoder error\n");
142
        printf("video decoder error\n");
112
 
143
 
Line 113... Line 144...
113
    if(frameFinished)
144
    if(frameFinished)
114
    {
145
    {
115
        vframe_t  *vframe;
146
        vframe_t  *vframe = vst->decoder_frame;;
116
        AVPicture *dst_pic;
147
        AVPicture *dst_pic;
Line -... Line 148...
-
 
148
 
-
 
149
        if(vst->hwdec)
-
 
150
            pts = pkt.pts;
117
 
151
        else
-
 
152
            pts = av_frame_get_best_effort_timestamp(Frame);
118
        pts = av_frame_get_best_effort_timestamp(Frame);
153
 
Line 119... Line -...
119
        pts *= av_q2d(video_time_base);
-
 
120
 
154
        pts*= av_q2d(video_time_base);
Line 121... Line 155...
121
        vframe  = vst->decoder_frame;
155
 
122
        dst_pic = &vframe->picture;
156
        dst_pic = &vframe->picture;
123
 
157
 
Line 132... Line 166...
132
        vframe->pkt_pts = pkt.pts*av_q2d(video_time_base)*1000.0;
166
        vframe->pkt_pts = pkt.pts*av_q2d(video_time_base)*1000.0;
133
        vframe->pkt_dts = dts*av_q2d(video_time_base)*1000.0;
167
        vframe->pkt_dts = dts*av_q2d(video_time_base)*1000.0;
134
        vframe->ready = 1;
168
        vframe->ready = 1;
135
 
169
 
Line 136... Line -...
136
 
-
 
137
        mutex_lock(&vst->output_lock);
170
        put_output_frame(vst, vframe);
138
 
-
 
139
        if(list_empty(&vst->output_list))
-
 
140
            list_add_tail(&vframe->list, &vst->output_list);
-
 
141
        else
-
 
142
        {
-
 
143
            vframe_t *cur;
-
 
144
 
-
 
145
            cur = list_first_entry(&vst->output_list,vframe_t,list);
-
 
146
            if(vframe->pkt_pts < cur->pkt_pts)
-
 
147
            {
-
 
148
                list_add_tail(&vframe->list, &vst->output_list);
-
 
149
            }
-
 
150
            else
-
 
151
            {
-
 
152
                list_for_each_entry_reverse(cur,&vst->output_list,list)
-
 
153
                {
-
 
154
                    if(vframe->pkt_pts > cur->pkt_pts)
-
 
155
                    {
-
 
156
                        list_add(&vframe->list, &cur->list);
-
 
157
                        break;
-
 
158
                    };
-
 
159
                };
-
 
160
            };
-
 
161
        };
-
 
162
        mutex_unlock(&vst->output_lock);
-
 
163
 
-
 
Line 164... Line 171...
164
 
171
 
165
//        printf("decoded index: %d pts: %f pkt_pts %f pkt_dts %f\n",
172
//        printf("decoded index: %d pts: %f pkt_pts %f pkt_dts %f\n",
166
//               vst->dfx, vst->vframe[vst->dfx].pts,
173
//               vst->dfx, vst->vframe[vst->dfx].pts,