Rev 6135 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6135 | Rev 6136 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | extern int64_t stream_duration; |
19 | extern int64_t stream_duration; |
20 | extern volatile int sound_level_0; |
20 | extern volatile int sound_level_0; |
21 | extern volatile int sound_level_1; |
21 | extern volatile int sound_level_1; |
Line 22... | Line -... | ||
22 | - | ||
23 | volatile int frames_count = 0; |
- | |
24 | 22 | ||
Line 25... | Line -... | ||
25 | struct SwsContext *cvt_ctx = NULL; |
- | |
26 | 23 | struct SwsContext *cvt_ctx = NULL; |
|
Line 27... | Line -... | ||
27 | - | ||
28 | render_t *main_render; |
- | |
29 | - | ||
30 | AVRational video_time_base; |
24 | |
31 | AVFrame *Frame; |
25 | render_t *main_render; |
32 | 26 | ||
33 | void get_client_rect(rect_t *rc); |
27 | void get_client_rect(rect_t *rc); |
Line 49... | Line 43... | ||
49 | { |
43 | { |
50 | vframe->pts = 0; |
44 | vframe->pts = 0; |
51 | vframe->ready = 0; |
45 | vframe->ready = 0; |
52 | } |
46 | } |
53 | 47 | vst->frames_count = 0; |
|
- | 48 | ||
Line 54... | Line 49... | ||
54 | mutex_unlock(&vst->input_lock); |
49 | mutex_unlock(&vst->input_lock); |
55 | mutex_unlock(&vst->output_lock); |
50 | mutex_unlock(&vst->output_lock); |
56 | - | ||
57 | frames_count = 0; |
- | |
58 | }; |
- | |
59 | - | ||
60 | int init_video(vst_t *vst) |
- | |
61 | { |
- | |
62 | Frame = av_frame_alloc(); |
- | |
63 | if ( Frame == NULL ) |
- | |
64 | { |
- | |
65 | printf("Cannot alloc video frame\n\r"); |
- | |
66 | return 0; |
- | |
67 | }; |
- | |
68 | - | ||
69 | mutex_lock(&vst->decoder_lock); |
- | |
70 | - | ||
71 | create_thread(video_thread, vst, 1024*1024); |
- | |
72 | - | ||
73 | return 1; |
- | |
74 | }; |
51 | }; |
Line 75... | Line -... | ||
75 | - | ||
Line 76... | Line 52... | ||
76 | static double dts = 0.0; |
52 | |
77 | 53 | ||
78 | static vframe_t *get_input_frame(vst_t *vst) |
54 | static vframe_t *get_input_frame(vst_t *vst) |
Line 113... | Line 89... | ||
113 | }; |
89 | }; |
114 | }; |
90 | }; |
115 | }; |
91 | }; |
116 | }; |
92 | }; |
117 | mutex_unlock(&vst->output_lock); |
93 | vst->frames_count++; |
- | 94 | mutex_unlock(&vst->output_lock); |
|
118 | }; |
95 | }; |
119 | 96 | ||
Line 120... | Line 97... | ||
120 | int decode_video(vst_t* vst) |
97 | int decode_video(vst_t* vst) |
121 | { |
98 | { |
122 | AVPacket pkt; |
- | |
123 | double pts; |
99 | double pts; |
- | 100 | AVPacket pkt; |
|
- | 101 | ||
124 | int frameFinished; |
102 | int frameFinished; |
Line 125... | Line 103... | ||
125 | 103 | ||
126 | if(vst->decoder_frame == NULL) |
104 | if(vst->decoder_frame == NULL) |
Line 127... | Line 105... | ||
127 | vst->decoder_frame = get_input_frame(vst); |
105 | vst->decoder_frame = get_input_frame(vst); |
128 | 106 | ||
Line 129... | Line 107... | ||
129 | if(vst->decoder_frame == NULL) |
107 | if(vst->decoder_frame == NULL) |
130 | return 0; |
108 | return -1; |
Line 131... | Line 109... | ||
131 | 109 | ||
132 | if( get_packet(&vst->q_video, &pkt) == 0 ) |
- | |
133 | return 0; |
- | |
Line 134... | Line 110... | ||
134 | 110 | if( get_packet(&vst->q_video, &pkt) == 0 ) |
|
Line 135... | Line 111... | ||
135 | frameFinished = 0; |
111 | return 0; |
136 | if(dts == 0) |
112 | |
Line 137... | Line 113... | ||
137 | dts = pkt.pts; |
113 | frameFinished = 0; |
138 | 114 | ||
139 | mutex_lock(&vst->gpu_lock); |
115 | mutex_lock(&vst->gpu_lock); |
140 | 116 | ||
Line 141... | Line 117... | ||
141 | if(avcodec_decode_video2(vst->vCtx, Frame, &frameFinished, &pkt) <= 0) |
117 | if(avcodec_decode_video2(vst->vCtx, vst->Frame, &frameFinished, &pkt) <= 0) |
142 | printf("video decoder error\n"); |
118 | printf("video decoder error\n"); |
143 | 119 | ||
144 | if(frameFinished) |
120 | if(frameFinished) |
Line 145... | Line 121... | ||
145 | { |
121 | { |
Line 146... | Line 122... | ||
146 | vframe_t *vframe = vst->decoder_frame;; |
122 | vframe_t *vframe = vst->decoder_frame;; |
Line 147... | Line 123... | ||
147 | AVPicture *dst_pic; |
123 | AVPicture *dst_pic; |
148 | 124 | ||
149 | if(vst->hwdec) |
125 | if(vst->hwdec) |
150 | pts = pkt.pts; |
126 | pts = pkt.pts; |
151 | else |
127 | else |
152 | pts = av_frame_get_best_effort_timestamp(Frame); |
128 | pts = av_frame_get_best_effort_timestamp(vst->Frame); |
Line 153... | Line 129... | ||
153 | 129 | ||
154 | pts*= av_q2d(video_time_base); |
130 | pts*= av_q2d(vst->video_time_base); |
155 | - | ||
156 | dst_pic = &vframe->picture; |
131 | |
Line 157... | Line 132... | ||
157 | 132 | dst_pic = &vframe->picture; |
|
Line 158... | Line 133... | ||
158 | if(vframe->is_hw_pic == 0) |
133 | |
159 | av_image_copy(dst_pic->data, dst_pic->linesize, |
134 | if(vframe->is_hw_pic == 0) |
160 | (const uint8_t**)Frame->data, |
135 | av_image_copy(dst_pic->data, dst_pic->linesize, |
Line 161... | Line 136... | ||
161 | Frame->linesize, vst->vCtx->pix_fmt, vst->vCtx->width, vst->vCtx->height); |
136 | (const uint8_t**)vst->Frame->data, |
162 | else |
- | |
163 | va_create_planar(vst, vframe); |
- | |
164 | 137 | vst->Frame->linesize, vst->vCtx->pix_fmt, vst->vCtx->width, vst->vCtx->height); |
|
165 | vframe->pts = pts*1000.0; |
138 | else |
166 | vframe->pkt_pts = pkt.pts*av_q2d(video_time_base)*1000.0; |
139 | va_create_planar(vst, vframe); |
Line 167... | Line 140... | ||
167 | vframe->pkt_dts = dts*av_q2d(video_time_base)*1000.0; |
140 | |
Line 168... | Line 141... | ||
168 | vframe->ready = 1; |
141 | vframe->pts = pts*1000.0; |
Line 415... | Line 388... | ||
415 | { |
388 | { |
416 | delay(1); |
389 | delay(1); |
417 | return; |
390 | return; |
418 | } |
391 | } |
419 | else if (decoder_state == STOP && frames_count == 0 && |
392 | else if (decoder_state == STOP && vst->frames_count == 0 && |
420 | player_state != STOP) |
393 | player_state != STOP) |
421 | { |
394 | { |
422 | player_stop(); |
395 | player_stop(); |
423 | } |
396 | } |
424 | else if(player_state != PLAY) |
397 | else if(player_state != PLAY) |
425 | { |
398 | { |
Line 439... | Line 412... | ||
439 | int sys_time; |
412 | int sys_time; |
440 | 413 | ||
Line 441... | Line 414... | ||
441 | vframe = list_first_entry(&vst->output_list, vframe_t, list); |
414 | vframe = list_first_entry(&vst->output_list, vframe_t, list); |
442 | list_del(&vframe->list); |
415 | list_del(&vframe->list); |
- | 416 | vst->frames_count--; |
|
443 | mutex_unlock(&vst->output_lock); |
417 | mutex_unlock(&vst->output_lock); |
Line 444... | Line 418... | ||
444 | 418 | ||
445 | ctime = get_master_clock(); |
419 | ctime = get_master_clock(); |
Line 446... | Line 420... | ||
446 | fdelay = (vframe->pkt_pts - ctime); |
420 | fdelay = (vframe->pts - ctime); |
447 | 421 | ||
448 | if(fdelay > 15.0) |
422 | if(fdelay > 15.0) |
449 | { |
423 | { |
Line 456... | Line 430... | ||
456 | main_render->draw(main_render, vframe); |
430 | main_render->draw(main_render, vframe); |
Line 457... | Line 431... | ||
457 | 431 | ||
458 | if(main_render->win->win_state != FULLSCREEN) |
432 | if(main_render->win->win_state != FULLSCREEN) |
459 | { |
433 | { |
460 | prg->current = vframe->pkt_pts * 1000; |
434 | prg->current = vframe->pts * 1000; |
Line 461... | Line 435... | ||
461 | lvl->current = vframe->index & 1 ? sound_level_1 : sound_level_0; |
435 | lvl->current = vframe->index & 1 ? sound_level_1 : sound_level_0; |
Line 462... | Line 436... | ||
462 | 436 | ||
463 | send_message(&prg->ctrl, PRG_PROGRESS, 0, 0); |
437 | send_message(&prg->ctrl, PRG_PROGRESS, 0, 0); |
464 | 438 | ||
Line 465... | Line -... | ||
465 | if(main_render->win->panel.layout) |
- | |
466 | send_message(&lvl->ctrl, MSG_PAINT, 0, 0); |
439 | if(main_render->win->panel.layout) |
Line 467... | Line 440... | ||
467 | } |
440 | send_message(&lvl->ctrl, MSG_PAINT, 0, 0); |
468 | 441 | } |
|
469 | frames_count--; |
442 | |
470 | vframe->ready = 0; |
443 | vframe->ready = 0; |
471 | 444 | ||
Line 472... | Line -... | ||
472 | mutex_lock(&vst->input_lock); |
- | |
473 | list_add_tail(&vframe->list, &vst->input_list); |
- | |
474 | mutex_unlock(&vst->input_lock); |
- | |
475 | } |
445 | mutex_lock(&vst->input_lock); |
476 | } |
446 | list_add_tail(&vframe->list, &vst->input_list); |
477 | 447 | mutex_unlock(&vst->input_lock); |
|
478 | 448 | } |
|
Line 479... | Line 449... | ||
479 | extern char *movie_file; |
449 | } |
Line 480... | Line 450... | ||
480 | 450 | ||
481 | int video_thread(void *param) |
451 | int video_thread(void *param) |
Line 482... | Line 452... | ||
482 | { |
452 | { |
Line 483... | Line 453... | ||
483 | vst_t *vst = param; |
453 | vst_t *vst = param; |