Rev 6136 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6136 | Rev 6144 | ||
---|---|---|---|
Line 38... | Line 38... | ||
38 | 38 | ||
Line 39... | Line 39... | ||
39 | list_for_each_entry_safe(vframe, tmp, &vst->output_list, list) |
39 | list_for_each_entry_safe(vframe, tmp, &vst->output_list, list) |
40 | list_move_tail(&vframe->list, &vst->input_list); |
40 | list_move_tail(&vframe->list, &vst->input_list); |
Line 41... | Line 41... | ||
41 | 41 | ||
42 | list_for_each_entry(vframe, &vst->output_list, list) |
42 | list_for_each_entry(vframe, &vst->input_list, list) |
43 | { |
43 | { |
44 | vframe->pts = 0; |
44 | vframe->pts = 0; |
45 | vframe->ready = 0; |
45 | vframe->ready = 0; |
46 | } |
46 | } |
Line 50... | Line 50... | ||
50 | mutex_unlock(&vst->output_lock); |
50 | mutex_unlock(&vst->output_lock); |
51 | }; |
51 | }; |
52 | 52 | ||
Line 53... | Line -... | ||
53 | - | ||
54 | static vframe_t *get_input_frame(vst_t *vst) |
- | |
55 | { |
- | |
56 | vframe_t *vframe = NULL; |
- | |
57 | - | ||
58 | mutex_lock(&vst->input_lock); |
- | |
59 | if(!list_empty(&vst->input_list)) |
- | |
60 | { |
- | |
61 | vframe = list_first_entry(&vst->input_list, vframe_t, list); |
- | |
62 | list_del(&vframe->list); |
- | |
63 | } |
- | |
64 | mutex_unlock(&vst->input_lock); |
- | |
65 | - | ||
66 | return vframe; |
- | |
67 | } |
- | |
68 | - | ||
69 | static void put_output_frame(vst_t *vst, vframe_t *vframe) |
- | |
70 | { |
- | |
71 | mutex_lock(&vst->output_lock); |
- | |
72 | if(list_empty(&vst->output_list)) |
- | |
73 | list_add_tail(&vframe->list, &vst->output_list); |
- | |
74 | else |
- | |
75 | { |
- | |
76 | vframe_t *cur; |
- | |
77 | - | ||
78 | cur = list_first_entry(&vst->output_list,vframe_t,list); |
- | |
79 | if(vframe->pts < cur->pts) |
- | |
80 | list_add_tail(&vframe->list, &vst->output_list); |
- | |
81 | else |
- | |
82 | { |
- | |
83 | list_for_each_entry_reverse(cur,&vst->output_list,list) |
- | |
84 | { |
- | |
85 | if(vframe->pts > cur->pts) |
- | |
86 | { |
- | |
87 | list_add(&vframe->list, &cur->list); |
- | |
88 | break; |
- | |
89 | }; |
- | |
90 | }; |
- | |
91 | }; |
- | |
92 | }; |
- | |
93 | vst->frames_count++; |
- | |
94 | mutex_unlock(&vst->output_lock); |
- | |
95 | }; |
- | |
96 | - | ||
97 | int decode_video(vst_t* vst) |
- | |
98 | { |
- | |
99 | double pts; |
- | |
100 | AVPacket pkt; |
- | |
101 | - | ||
102 | int frameFinished; |
- | |
103 | - | ||
104 | if(vst->decoder_frame == NULL) |
- | |
105 | vst->decoder_frame = get_input_frame(vst); |
- | |
106 | - | ||
107 | if(vst->decoder_frame == NULL) |
- | |
108 | return -1; |
- | |
109 | - | ||
110 | if( get_packet(&vst->q_video, &pkt) == 0 ) |
- | |
111 | return 0; |
- | |
112 | - | ||
113 | frameFinished = 0; |
- | |
114 | - | ||
115 | mutex_lock(&vst->gpu_lock); |
- | |
116 | - | ||
117 | if(avcodec_decode_video2(vst->vCtx, vst->Frame, &frameFinished, &pkt) <= 0) |
- | |
118 | printf("video decoder error\n"); |
- | |
119 | - | ||
120 | if(frameFinished) |
- | |
121 | { |
- | |
122 | vframe_t *vframe = vst->decoder_frame;; |
- | |
123 | AVPicture *dst_pic; |
- | |
124 | - | ||
125 | if(vst->hwdec) |
- | |
126 | pts = pkt.pts; |
- | |
127 | else |
- | |
128 | pts = av_frame_get_best_effort_timestamp(vst->Frame); |
- | |
129 | - | ||
130 | pts*= av_q2d(vst->video_time_base); |
- | |
131 | - | ||
132 | dst_pic = &vframe->picture; |
- | |
133 | - | ||
134 | if(vframe->is_hw_pic == 0) |
- | |
135 | av_image_copy(dst_pic->data, dst_pic->linesize, |
- | |
136 | (const uint8_t**)vst->Frame->data, |
- | |
137 | vst->Frame->linesize, vst->vCtx->pix_fmt, vst->vCtx->width, vst->vCtx->height); |
- | |
138 | else |
- | |
139 | va_create_planar(vst, vframe); |
- | |
140 | - | ||
141 | vframe->pts = pts*1000.0; |
- | |
142 | vframe->pkt_pts = pkt.pts*av_q2d(vst->video_time_base)*1000.0; |
- | |
143 | vframe->ready = 1; |
- | |
144 | - | ||
145 | put_output_frame(vst, vframe); |
- | |
146 | - | ||
147 | // printf("decoded index: %d pts: %f pkt_pts %f pkt_dts %f\n", |
- | |
148 | // vst->dfx, vst->vframe[vst->dfx].pts, |
- | |
149 | // vst->vframe[vst->dfx].pkt_pts, vst->vframe[vst->dfx].pkt_dts); |
- | |
150 | - | ||
151 | vst->decoder_frame = NULL; |
- | |
152 | }; |
- | |
153 | av_frame_unref(vst->Frame); |
- | |
154 | mutex_unlock(&vst->gpu_lock); |
- | |
155 | - | ||
156 | av_free_packet(&pkt); |
- | |
157 | - | ||
158 | return 1; |
- | |
Line 159... | Line 53... | ||
159 | } |
53 | |
160 | 54 | ||
161 | extern volatile enum player_state player_state; |
55 | extern volatile enum player_state player_state; |
Line 480... | Line 374... | ||
480 | run_render(MainWindow, main_render); |
374 | run_render(MainWindow, main_render); |
Line 481... | Line 375... | ||
481 | 375 | ||
Line -... | Line 376... | ||
- | 376 | __sync_and_and_fetch(&threads_running,~VIDEO_THREAD); |
|
- | 377 | ||
- | 378 | { |
|
- | 379 | vframe_t *vframe, *tmp; |
|
- | 380 | flush_video(vst); |
|
- | 381 | ||
- | 382 | list_for_each_entry_safe(vframe, tmp, &vst->output_list, list) |
|
- | 383 | { |
|
- | 384 | list_del(&vframe->list); |
|
- | 385 | if(vframe->planar != NULL) |
|
- | 386 | pxDestroyPlanar(vframe->planar); |
|
- | 387 | } |
|
482 | __sync_and_and_fetch(&threads_running,~VIDEO_THREAD); |
388 | } |
483 | 389 | ||
484 | destroy_render(main_render); |
390 | destroy_render(main_render); |
485 | fini_winlib(); |
391 | fini_winlib(); |
486 | player_state = CLOSED; |
392 | player_state = CLOSED; |
Line 735... | Line 641... | ||
735 | pxBlitPlanar(planar, render->rcvideo.l, |
641 | pxBlitPlanar(planar, render->rcvideo.l, |
736 | CAPTION_HEIGHT+render->rcvideo.t, |
642 | CAPTION_HEIGHT+render->rcvideo.t, |
737 | render->rcvideo.r, render->rcvideo.b,0,0); |
643 | render->rcvideo.r, render->rcvideo.b,0,0); |
738 | mutex_unlock(&render->vst->gpu_lock); |
644 | mutex_unlock(&render->vst->gpu_lock); |
739 | - | ||
740 | } |
645 | } |
741 | }; |
646 | }; |
Line 742... | Line 647... | ||
742 | 647 | ||
743 | void draw_hw_picture(render_t *render, vframe_t *vframe) |
648 | void draw_hw_picture(render_t *render, vframe_t *vframe) |
Line 768... | Line 673... | ||
768 | dst_width = render->rcvideo.r; |
673 | dst_width = render->rcvideo.r; |
769 | dst_height = render->rcvideo.b; |
674 | dst_height = render->rcvideo.b; |
770 | }; |
675 | }; |
771 | 676 | ||
Line 772... | Line 677... | ||
772 | if(vst->hwdec) |
677 | if(vframe->is_hw_pic) |
773 | { |
678 | { |
774 | render_hw_planar(render, vframe); |
679 | render_hw_planar(render, vframe); |
775 | return; |
680 | return; |
776 | }; |
681 | }; |
Line 777... | Line 682... | ||
777 | 682 | ||
Line 778... | Line 683... | ||
778 | picture = &vframe->picture; |
683 | picture = &vframe->picture; |
779 | 684 | ||
780 | format = render->vst->hwdec == 0 ? render->ctx_format : AV_PIX_FMT_BGRA; |
685 | format = render->ctx_format; |
781 | cvt_ctx = sws_getCachedContext(cvt_ctx, render->ctx_width, render->ctx_height, format, |
686 | cvt_ctx = sws_getCachedContext(cvt_ctx, render->ctx_width, render->ctx_height, format, |
782 | dst_width, dst_height, AV_PIX_FMT_BGRA, |
687 | dst_width, dst_height, AV_PIX_FMT_BGRA, |
783 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |
688 | SWS_FAST_BILINEAR, NULL, NULL, NULL); |