Rev 6133 | Rev 6144 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6133 | Rev 6136 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | 14 | ||
Line 15... | Line 15... | ||
15 | #include "sound.h" |
15 | #include "sound.h" |
16 | #include "fplay.h" |
16 | #include "fplay.h" |
Line 17... | Line -... | ||
17 | - | ||
18 | #ifdef HAVE_VAAPI |
- | |
19 | int va_check_codec_support(enum AVCodecID id); |
- | |
20 | #endif |
- | |
21 | 17 | ||
22 | volatile enum player_state player_state = STOP; |
18 | volatile enum player_state player_state = STOP; |
23 | volatile enum player_state decoder_state = PREPARE; |
19 | volatile enum player_state decoder_state = PREPARE; |
Line 24... | Line 20... | ||
24 | volatile enum player_state sound_state = STOP; |
20 | volatile enum player_state sound_state = STOP; |
Line 25... | Line 21... | ||
25 | 21 | ||
Line 26... | Line 22... | ||
26 | uint32_t win_width, win_height; |
22 | uint32_t win_width, win_height; |
27 | 23 | ||
28 | int have_sound = 0; |
- | |
29 | 24 | int have_sound = 0; |
|
30 | uint8_t *decoder_buffer; |
- | |
31 | extern int resampler_size; |
- | |
32 | - | ||
33 | extern int sample_rate; |
- | |
Line 34... | Line 25... | ||
34 | char *movie_file; |
25 | |
Line 35... | Line 26... | ||
35 | 26 | uint8_t *decoder_buffer; |
|
Line 36... | Line 27... | ||
36 | void flush_video(vst_t* vst); |
27 | extern int resampler_size; |
Line 37... | Line 28... | ||
37 | 28 | extern int sample_rate; |
|
Line 38... | Line -... | ||
38 | - | ||
39 | int64_t rewind_pos; |
- | |
40 | - | ||
41 | int64_t stream_duration; |
- | |
42 | - | ||
43 | int threads_running = DECODER_THREAD; |
- | |
44 | 29 | ||
45 | extern double audio_base; |
30 | int64_t rewind_pos; |
46 | 31 | ||
47 | 32 | int64_t stream_duration; |
|
48 | double get_audio_base(vst_t* vst) |
33 | |
Line 49... | Line 34... | ||
49 | { |
34 | int threads_running = DECODER_THREAD; |
50 | return (double)av_q2d(vst->fCtx->streams[vst->aStream]->time_base)*1000; |
35 | |
51 | }; |
36 | extern double audio_base; |
52 | 37 | ||
53 | 38 | ||
54 | int main( int argc, char *argv[]) |
39 | int main( int argc, char *argv[]) |
55 | { |
40 | { |
56 | static vst_t vst; |
41 | static vst_t vst; |
57 | int i, ret; |
42 | int i, ret; |
58 | char *file_name, *dot; |
43 | char *file_name, *dot; |
Line 59... | Line 44... | ||
59 | 44 | ||
Line 60... | Line 45... | ||
60 | if(argc < 2) |
45 | if(argc < 2) |
Line 61... | Line 46... | ||
61 | { |
46 | { |
62 | movie_file = get_moviefile(); |
47 | vst.input_file = get_moviefile(); |
63 | if(movie_file == NULL) |
48 | if(vst.input_file == NULL) |
Line 64... | Line 49... | ||
64 | { |
49 | { |
65 | printf("Please provide a movie file\n"); |
50 | printf("Please provide a movie file\n"); |
66 | return -1; |
51 | return -1; |
67 | } |
52 | } |
68 | } |
53 | } |
Line 69... | Line 54... | ||
69 | else movie_file = argv[1]; |
54 | else vst.input_file = argv[1]; |
Line 90... | Line 75... | ||
90 | printf("Cannot find streams\n\r"); |
75 | printf("Cannot find streams\n\r"); |
91 | return -1; |
76 | return -1; |
92 | }; |
77 | }; |
93 | 78 | ||
Line 94... | Line 79... | ||
94 | file_name = strrchr(movie_file,'/')+1; |
79 | file_name = strrchr(vst.input_file,'/')+1; |
95 | dot = strrchr(file_name,'.'); |
80 | dot = strrchr(file_name,'.'); |
96 | if(dot) |
81 | if(dot) |
97 | { |
82 | { |
98 | movie_file = malloc(dot-file_name+1); |
83 | vst.input_name = malloc(dot-file_name+1); |
99 | memcpy(movie_file, file_name, dot-file_name); |
84 | memcpy(vst.input_name, file_name, dot-file_name); |
100 | movie_file[dot-file_name] = 0; |
85 | vst.input_name[dot-file_name] = 0; |
101 | } |
86 | } |
102 | else movie_file = file_name; |
87 | else vst.input_name = file_name; |
Line 103... | Line 88... | ||
103 | 88 | ||
Line 104... | Line 89... | ||
104 | stream_duration = vst.fCtx->duration; |
89 | stream_duration = vst.fCtx->duration; |
105 | 90 | ||
Line 112... | Line 97... | ||
112 | if(vst.fCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO |
97 | if(vst.fCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO |
113 | && vst.vStream < 0) |
98 | && vst.vStream < 0) |
114 | { |
99 | { |
115 | vst.vStream = i; |
100 | vst.vStream = i; |
116 | video_time_base = vst.fCtx->streams[i]->time_base; |
101 | vst.video_time_base = vst.fCtx->streams[i]->time_base; |
117 | if(stream_duration == 0) |
102 | if(stream_duration == 0) |
118 | stream_duration = vst.fCtx->streams[i]->duration; |
103 | stream_duration = vst.fCtx->streams[i]->duration; |
119 | } |
104 | } |
120 | 105 | ||
Line 121... | Line 106... | ||
121 | if(vst.fCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO && |
106 | if(vst.fCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO && |
122 | vst.aStream < 0) |
107 | vst.aStream < 0) |
123 | { |
108 | { |
124 | vst.aStream = i; |
109 | vst.aStream = i; |
- | 110 | vst.audio_time_base = vst.fCtx->streams[i]->time_base; |
|
125 | if(stream_duration == 0) |
111 | if(stream_duration == 0) |
126 | stream_duration = vst.fCtx->streams[i]->duration; |
112 | stream_duration = vst.fCtx->streams[i]->duration; |
127 | } |
113 | } |
128 | } |
114 | } |
Line 139... | Line 125... | ||
139 | vst.vCtx = vst.fCtx->streams[vst.vStream]->codec; |
125 | vst.vCtx = vst.fCtx->streams[vst.vStream]->codec; |
140 | vst.aCtx = vst.fCtx->streams[vst.aStream]->codec; |
126 | vst.aCtx = vst.fCtx->streams[vst.aStream]->codec; |
141 | 127 | ||
Line 142... | Line 128... | ||
142 | vst.vCodec = avcodec_find_decoder(vst.vCtx->codec_id); |
128 | vst.vCodec = avcodec_find_decoder(vst.vCtx->codec_id); |
143 | printf("codec id %x name %s\n",vst.vCtx->codec_id, vst.vCodec->name); |
- | |
144 | printf("ctx->pix_fmt %d\n", vst.vCtx->pix_fmt); |
- | |
Line 145... | Line 129... | ||
145 | 129 | ||
146 | INIT_LIST_HEAD(&vst.input_list); |
130 | INIT_LIST_HEAD(&vst.input_list); |
147 | INIT_LIST_HEAD(&vst.output_list); |
131 | INIT_LIST_HEAD(&vst.output_list); |
148 | mutex_init(&vst.q_video.lock); |
132 | mutex_init(&vst.q_video.lock); |
Line 155... | Line 139... | ||
155 | if(vst.vCodec == NULL) |
139 | if(vst.vCodec == NULL) |
156 | { |
140 | { |
157 | printf("Unsupported codec with id %d for input stream %d\n", |
141 | printf("Unsupported codec with id %d for input stream %d\n", |
158 | vst.vCtx->codec_id, vst.vStream); |
142 | vst.vCtx->codec_id, vst.vStream); |
159 | return -1; // Codec not found |
143 | return -1; |
160 | } |
144 | } |
Line -... | Line 145... | ||
- | 145 | ||
- | 146 | vst.Frame = av_frame_alloc(); |
|
- | 147 | if(vst.Frame == NULL) |
|
- | 148 | { |
|
- | 149 | printf("Cannot alloc video frame\n"); |
|
- | 150 | return -1; |
|
- | 151 | }; |
|
161 | 152 | ||
162 | if(fplay_init_context(&vst)) |
153 | if(fplay_init_context(&vst)) |
Line 163... | Line 154... | ||
163 | return -1; |
154 | return -1; |
164 | 155 | ||
165 | if(avcodec_open2(vst.vCtx, vst.vCodec, NULL) < 0) |
156 | if(avcodec_open2(vst.vCtx, vst.vCodec, NULL) < 0) |
166 | { |
157 | { |
167 | printf("Error while opening codec for input stream %d\n", |
158 | printf("Error while opening codec for input stream %d\n", |
168 | vst.vStream); |
159 | vst.vStream); |
Line 169... | Line -... | ||
169 | return -1; // Could not open codec |
- | |
170 | }; |
- | |
171 | 160 | return -1; // Could not open codec |
|
172 | printf("ctx->pix_fmt %d\n", vst.vCtx->pix_fmt); |
161 | }; |
173 | 162 | ||
174 | if (vst.aCtx->channels > 0) |
163 | if (vst.aCtx->channels > 0) |
Line 221... | Line 210... | ||
221 | else printf("Cannot open audio codec\n\r"); |
210 | else printf("Cannot open audio codec\n\r"); |
222 | } |
211 | } |
223 | else printf("Unsupported audio codec!\n"); |
212 | else printf("Unsupported audio codec!\n"); |
224 | 213 | ||
Line 225... | Line 214... | ||
225 | if(!init_video(&vst)) |
214 | mutex_lock(&vst.decoder_lock); |
226 | return 0; |
215 | create_thread(video_thread, &vst, 1024*1024); |
227 | - | ||
228 | mutex_lock_timeout(&vst.decoder_lock, 3000); |
216 | if(mutex_lock_timeout(&vst.decoder_lock, 3000) == 0) |
- | 217 | return -1; |
|
Line 229... | Line 218... | ||
229 | 218 | ||
Line 230... | Line 219... | ||
230 | decoder(&vst); |
219 | decoder(&vst); |
Line 367... | Line 356... | ||
367 | }; |
356 | }; |
368 | delay(1); |
357 | delay(1); |
369 | continue; |
358 | continue; |
370 | } |
359 | } |
371 | 360 | yield(); |
|
372 | yield(); |
- | |
373 | continue; |
361 | continue; |
374 | 362 | ||
Line 375... | Line 363... | ||
375 | case STOP: |
363 | case STOP: |
376 | delay(1); |
364 | delay(1); |