diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2006-06-18 15:11:06 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-25 01:05:22 -0400 |
commit | f022156b33ffa32c26a86540fe4f6fe56cff0963 (patch) | |
tree | ba896ea08b1215135986fe353a39bfbd0db2f5de /drivers/media | |
parent | 54f577b7f46f48b8bea0bd5eb8c42d711b3e006f (diff) |
V4L/DVB (4196): Port cx88-blackbird to the new MPEG API.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/video/cx88/cx88-blackbird.c | 771 | ||||
-rw-r--r-- | drivers/media/video/cx88/cx88.h | 16 |
2 files changed, 74 insertions, 713 deletions
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c index f366b86e4693..9fa1ddbe3fd8 100644 --- a/drivers/media/video/cx88/cx88-blackbird.c +++ b/drivers/media/video/cx88/cx88-blackbird.c | |||
@@ -84,163 +84,11 @@ enum blackbird_framerate { | |||
84 | BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */ | 84 | BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */ |
85 | BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */ | 85 | BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */ |
86 | }; | 86 | }; |
87 | enum blackbird_video_bitrate_type { | ||
88 | BLACKBIRD_VIDEO_VBR, | ||
89 | BLACKBIRD_VIDEO_CBR | ||
90 | }; | ||
91 | #define BLACKBIRD_PEAK_RATE_DIVISOR 400 | ||
92 | enum blackbird_mux_rate { | ||
93 | BLACKBIRD_MUX_RATE_DEFAULT, | ||
94 | /* dvd mux rate: multiply by 400 to get the actual rate */ | ||
95 | BLACKBIRD_MUX_RATE_DVD = 25200 | ||
96 | }; | ||
97 | enum blackbird_aspect_ratio { | ||
98 | BLACKBIRD_ASPECT_RATIO_FORBIDDEN, | ||
99 | BLACKBIRD_ASPECT_RATIO_1_1_SQUARE, | ||
100 | BLACKBIRD_ASPECT_RATIO_4_3, | ||
101 | BLACKBIRD_ASPECT_RATIO_16_9, | ||
102 | BLACKBIRD_ASPECT_RATIO_221_100, | ||
103 | BLACKBIRD_ASPECT_RATIO_RESERVED | ||
104 | }; | ||
105 | enum blackbird_dnr_bits { | ||
106 | BLACKBIRD_DNR_BITS_MANUAL, | ||
107 | BLACKBIRD_DNR_BITS_AUTO_SPATIAL, | ||
108 | BLACKBIRD_DNR_BITS_AUTO_TEMPORAL, | ||
109 | BLACKBIRD_DNR_BITS_AUTO | ||
110 | }; | ||
111 | enum blackbird_median_filter { | ||
112 | BLACKBIRD_MEDIAN_FILTER_DISABLED, | ||
113 | BLACKBIRD_MEDIAN_FILTER_HORIZONTAL, | ||
114 | BLACKBIRD_MEDIAN_FILTER_VERTICAL, | ||
115 | BLACKBIRD_MEDIAN_FILTER_HV, | ||
116 | BLACKBIRD_MEDIAN_FILTER_DIAGONAL | ||
117 | }; | ||
118 | enum blackbird_spatial_filter_luma { | ||
119 | BLACKBIRD_SPATIAL_FILTER_LUMA_DISABLED, | ||
120 | BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ, | ||
121 | BLACKBIRD_SPATIAL_FILTER_LUMA_1D_VERT, | ||
122 | BLACKBIRD_SPATIAL_FILTER_LUMA_2D_HV, /* separable, default */ | ||
123 | BLACKBIRD_SPATIAL_FILTER_LUMA_2D_SYMM /* symmetric non-separable */ | ||
124 | }; | ||
125 | enum blackbird_spatial_filter_chroma { | ||
126 | BLACKBIRD_SPATIAL_FILTER_CHROMA_DISABLED, | ||
127 | BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ /* default */ | ||
128 | }; | ||
129 | enum blackbird_pulldown { | ||
130 | BLACKBIRD_3_2_PULLDOWN_DISABLED, | ||
131 | BLACKBIRD_3_2_PULLDOWN_ENABLED | ||
132 | }; | ||
133 | enum blackbird_vbi_line_bits { | ||
134 | BLACKBIRD_VBI_LINE_BITS_TOP_FIELD, | ||
135 | BLACKBIRD_VBI_LINE_BITS_BOT_FIELD = (1 << 31), | ||
136 | BLACKBIRD_VBI_LINE_BITS_ALL_LINES = 0xFFFFFFFF | ||
137 | }; | ||
138 | enum blackbird_vbi_line { | ||
139 | BLACKBIRD_VBI_LINE_DISABLED, | ||
140 | BLACKBIRD_VBI_LINE_ENABLED | ||
141 | }; | ||
142 | enum blackbird_vbi_slicing { | ||
143 | BLACKBIRD_VBI_SLICING_NONE, | ||
144 | BLACKBIRD_VBI_SLICING_CLOSED_CAPTION | ||
145 | }; | ||
146 | enum blackbird_stream_type { | ||
147 | BLACKBIRD_STREAM_PROGRAM, | ||
148 | BLACKBIRD_STREAM_TRANSPORT, | ||
149 | BLACKBIRD_STREAM_MPEG1, | ||
150 | BLACKBIRD_STREAM_PES_AV, | ||
151 | BLACKBIRD_STREAM_UNKNOWN4, | ||
152 | BLACKBIRD_STREAM_PES_VIDEO, | ||
153 | BLACKBIRD_STREAM_UNKNOWN6, | ||
154 | BLACKBIRD_STREAM_PES_AUDIO, | ||
155 | BLACKBIRD_STREAM_UNKNOWN8, | ||
156 | BLACKBIRD_STREAM_UNKNOWN9, /* audio/pcm ? */ | ||
157 | BLACKBIRD_STREAM_DVD, | ||
158 | BLACKBIRD_STREAM_VCD, | ||
159 | BLACKBIRD_STREAM_UNKNOWN12 /* svcd/xvcd ? */ | ||
160 | }; | ||
161 | enum blackbird_stream_port { | 87 | enum blackbird_stream_port { |
162 | BLACKBIRD_OUTPUT_PORT_MEMORY, | 88 | BLACKBIRD_OUTPUT_PORT_MEMORY, |
163 | BLACKBIRD_OUTPUT_PORT_STREAMING, | 89 | BLACKBIRD_OUTPUT_PORT_STREAMING, |
164 | BLACKBIRD_OUTPUT_PORT_SERIAL | 90 | BLACKBIRD_OUTPUT_PORT_SERIAL |
165 | }; | 91 | }; |
166 | enum blackbird_audio_bits_sample_rate { | ||
167 | BLACKBIRD_AUDIO_BITS_44100HZ, | ||
168 | BLACKBIRD_AUDIO_BITS_48000HZ, | ||
169 | BLACKBIRD_AUDIO_BITS_32000HZ, | ||
170 | BLACKBIRD_AUDIO_BITS_RESERVED_HZ, | ||
171 | }; | ||
172 | enum blackbird_audio_bits_encoding { | ||
173 | BLACKBIRD_AUDIO_BITS_LAYER_1 = 0x1 << 2, | ||
174 | BLACKBIRD_AUDIO_BITS_LAYER_2 = 0x2 << 2, | ||
175 | }; | ||
176 | enum blackbird_audio_bits_bitrate_layer_1 { | ||
177 | BLACKBIRD_AUDIO_BITS_LAYER_1_FREE_FORMAT, | ||
178 | BLACKBIRD_AUDIO_BITS_LAYER_1_32 = 0x01 << 4, | ||
179 | BLACKBIRD_AUDIO_BITS_LAYER_1_64 = 0x02 << 4, | ||
180 | BLACKBIRD_AUDIO_BITS_LAYER_1_96 = 0x03 << 4, | ||
181 | BLACKBIRD_AUDIO_BITS_LAYER_1_128 = 0x04 << 4, | ||
182 | BLACKBIRD_AUDIO_BITS_LAYER_1_160 = 0x05 << 4, | ||
183 | BLACKBIRD_AUDIO_BITS_LAYER_1_192 = 0x06 << 4, | ||
184 | BLACKBIRD_AUDIO_BITS_LAYER_1_224 = 0x07 << 4, | ||
185 | BLACKBIRD_AUDIO_BITS_LAYER_1_256 = 0x08 << 4, | ||
186 | BLACKBIRD_AUDIO_BITS_LAYER_1_288 = 0x09 << 4, | ||
187 | BLACKBIRD_AUDIO_BITS_LAYER_1_320 = 0x0A << 4, | ||
188 | BLACKBIRD_AUDIO_BITS_LAYER_1_352 = 0x0B << 4, | ||
189 | BLACKBIRD_AUDIO_BITS_LAYER_1_384 = 0x0C << 4, | ||
190 | BLACKBIRD_AUDIO_BITS_LAYER_1_416 = 0x0D << 4, | ||
191 | BLACKBIRD_AUDIO_BITS_LAYER_1_448 = 0x0E << 4, | ||
192 | }; | ||
193 | enum blackbird_audio_bits_bitrate_layer_2 { | ||
194 | BLACKBIRD_AUDIO_BITS_LAYER_2_FREE_FORMAT, | ||
195 | BLACKBIRD_AUDIO_BITS_LAYER_2_32 = 0x01 << 4, | ||
196 | BLACKBIRD_AUDIO_BITS_LAYER_2_48 = 0x02 << 4, | ||
197 | BLACKBIRD_AUDIO_BITS_LAYER_2_56 = 0x03 << 4, | ||
198 | BLACKBIRD_AUDIO_BITS_LAYER_2_64 = 0x04 << 4, | ||
199 | BLACKBIRD_AUDIO_BITS_LAYER_2_80 = 0x05 << 4, | ||
200 | BLACKBIRD_AUDIO_BITS_LAYER_2_96 = 0x06 << 4, | ||
201 | BLACKBIRD_AUDIO_BITS_LAYER_2_112 = 0x07 << 4, | ||
202 | BLACKBIRD_AUDIO_BITS_LAYER_2_128 = 0x08 << 4, | ||
203 | BLACKBIRD_AUDIO_BITS_LAYER_2_160 = 0x09 << 4, | ||
204 | BLACKBIRD_AUDIO_BITS_LAYER_2_192 = 0x0A << 4, | ||
205 | BLACKBIRD_AUDIO_BITS_LAYER_2_224 = 0x0B << 4, | ||
206 | BLACKBIRD_AUDIO_BITS_LAYER_2_256 = 0x0C << 4, | ||
207 | BLACKBIRD_AUDIO_BITS_LAYER_2_320 = 0x0D << 4, | ||
208 | BLACKBIRD_AUDIO_BITS_LAYER_2_384 = 0x0E << 4, | ||
209 | }; | ||
210 | enum blackbird_audio_bits_mode { | ||
211 | BLACKBIRD_AUDIO_BITS_STEREO, | ||
212 | BLACKBIRD_AUDIO_BITS_JOINT_STEREO = 0x1 << 8, | ||
213 | BLACKBIRD_AUDIO_BITS_DUAL = 0x2 << 8, | ||
214 | BLACKBIRD_AUDIO_BITS_MONO = 0x3 << 8, | ||
215 | }; | ||
216 | enum blackbird_audio_bits_mode_extension { | ||
217 | BLACKBIRD_AUDIO_BITS_BOUND_4, | ||
218 | BLACKBIRD_AUDIO_BITS_BOUND_8 = 0x1 << 10, | ||
219 | BLACKBIRD_AUDIO_BITS_BOUND_12 = 0x2 << 10, | ||
220 | BLACKBIRD_AUDIO_BITS_BOUND_16 = 0x3 << 10, | ||
221 | }; | ||
222 | enum blackbird_audio_bits_emphasis { | ||
223 | BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE, | ||
224 | BLACKBIRD_AUDIO_BITS_EMPHASIS_50_15 = 0x1 << 12, | ||
225 | BLACKBIRD_AUDIO_BITS_EMPHASIS_RESERVED = 0x2 << 12, | ||
226 | BLACKBIRD_AUDIO_BITS_EMPHASIS_CCITT_J17 = 0x3 << 12, | ||
227 | }; | ||
228 | enum blackbird_audio_bits_crc { | ||
229 | BLACKBIRD_AUDIO_BITS_CRC_OFF, | ||
230 | BLACKBIRD_AUDIO_BITS_CRC_ON = 0x1 << 14, | ||
231 | }; | ||
232 | enum blackbird_audio_bits_copyright { | ||
233 | BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF, | ||
234 | BLACKBIRD_AUDIO_BITS_COPYRIGHT_ON = 0x1 << 15, | ||
235 | }; | ||
236 | enum blackbird_audio_bits_original { | ||
237 | BLACKBIRD_AUDIO_BITS_COPY, | ||
238 | BLACKBIRD_AUDIO_BITS_ORIGINAL = 0x1 << 16, | ||
239 | }; | ||
240 | enum blackbird_gop_closure { | ||
241 | BLACKBIRD_GOP_CLOSURE_OFF, | ||
242 | BLACKBIRD_GOP_CLOSURE_ON, | ||
243 | }; | ||
244 | enum blackbird_data_xfer_status { | 92 | enum blackbird_data_xfer_status { |
245 | BLACKBIRD_MORE_BUFFERS_FOLLOW, | 93 | BLACKBIRD_MORE_BUFFERS_FOLLOW, |
246 | BLACKBIRD_LAST_BUFFER, | 94 | BLACKBIRD_LAST_BUFFER, |
@@ -458,15 +306,12 @@ static int register_read(struct cx88_core *core, u32 address, u32 *value) | |||
458 | 306 | ||
459 | /* ------------------------------------------------------------------ */ | 307 | /* ------------------------------------------------------------------ */ |
460 | 308 | ||
461 | /* We don't need to call the API often, so using just one mailbox will probably suffice */ | 309 | static int blackbird_mbox_func(void *priv, int command, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]) |
462 | static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, | ||
463 | u32 inputcnt, u32 outputcnt, ...) | ||
464 | { | 310 | { |
311 | struct cx8802_dev *dev = priv; | ||
465 | unsigned long timeout; | 312 | unsigned long timeout; |
466 | u32 value, flag, retval; | 313 | u32 value, flag, retval; |
467 | int i; | 314 | int i; |
468 | va_list args; | ||
469 | va_start(args, outputcnt); | ||
470 | 315 | ||
471 | dprintk(1,"%s: 0x%X\n", __FUNCTION__, command); | 316 | dprintk(1,"%s: 0x%X\n", __FUNCTION__, command); |
472 | 317 | ||
@@ -490,12 +335,11 @@ static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, | |||
490 | /* write command + args + fill remaining with zeros */ | 335 | /* write command + args + fill remaining with zeros */ |
491 | memory_write(dev->core, dev->mailbox + 1, command); /* command code */ | 336 | memory_write(dev->core, dev->mailbox + 1, command); /* command code */ |
492 | memory_write(dev->core, dev->mailbox + 3, IVTV_API_STD_TIMEOUT); /* timeout */ | 337 | memory_write(dev->core, dev->mailbox + 3, IVTV_API_STD_TIMEOUT); /* timeout */ |
493 | for (i = 0; i < inputcnt ; i++) { | 338 | for (i = 0; i < in; i++) { |
494 | value = va_arg(args, int); | 339 | memory_write(dev->core, dev->mailbox + 4 + i, data[i]); |
495 | memory_write(dev->core, dev->mailbox + 4 + i, value); | 340 | dprintk(1, "API Input %d = %d\n", i, data[i]); |
496 | dprintk(1, "API Input %d = %d\n", i, value); | ||
497 | } | 341 | } |
498 | for (; i < 16 ; i++) | 342 | for (; i < CX2341X_MBOX_MAX_DATA; i++) |
499 | memory_write(dev->core, dev->mailbox + 4 + i, 0); | 343 | memory_write(dev->core, dev->mailbox + 4 + i, 0); |
500 | 344 | ||
501 | flag |= 3; /* tell 'em we're done writing */ | 345 | flag |= 3; /* tell 'em we're done writing */ |
@@ -515,12 +359,10 @@ static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, | |||
515 | } | 359 | } |
516 | 360 | ||
517 | /* read output values */ | 361 | /* read output values */ |
518 | for (i = 0; i < outputcnt ; i++) { | 362 | for (i = 0; i < out; i++) { |
519 | int *vptr = va_arg(args, int *); | 363 | memory_read(dev->core, dev->mailbox + 4 + i, data + i); |
520 | memory_read(dev->core, dev->mailbox + 4 + i, vptr); | 364 | dprintk(1, "API Output %d = %d\n", i, data[i]); |
521 | dprintk(1, "API Output %d = %d\n", i, *vptr); | ||
522 | } | 365 | } |
523 | va_end(args); | ||
524 | 366 | ||
525 | memory_read(dev->core, dev->mailbox + 2, &retval); | 367 | memory_read(dev->core, dev->mailbox + 2, &retval); |
526 | dprintk(1, "API result = %d\n",retval); | 368 | dprintk(1, "API result = %d\n",retval); |
@@ -529,7 +371,29 @@ static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, | |||
529 | memory_write(dev->core, dev->mailbox, flag); | 371 | memory_write(dev->core, dev->mailbox, flag); |
530 | return retval; | 372 | return retval; |
531 | } | 373 | } |
374 | /* ------------------------------------------------------------------ */ | ||
532 | 375 | ||
376 | /* We don't need to call the API often, so using just one mailbox will probably suffice */ | ||
377 | static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, | ||
378 | u32 inputcnt, u32 outputcnt, ...) | ||
379 | { | ||
380 | u32 data[CX2341X_MBOX_MAX_DATA]; | ||
381 | va_list vargs; | ||
382 | int i, err; | ||
383 | |||
384 | va_start(vargs, outputcnt); | ||
385 | |||
386 | for (i = 0; i < inputcnt; i++) { | ||
387 | data[i] = va_arg(vargs, int); | ||
388 | } | ||
389 | err = blackbird_mbox_func(dev, command, inputcnt, outputcnt, data); | ||
390 | for (i = 0; i < outputcnt; i++) { | ||
391 | int *vptr = va_arg(vargs, int *); | ||
392 | *vptr = data[i]; | ||
393 | } | ||
394 | va_end(vargs); | ||
395 | return err; | ||
396 | } | ||
533 | 397 | ||
534 | static int blackbird_find_mailbox(struct cx8802_dev *dev) | 398 | static int blackbird_find_mailbox(struct cx8802_dev *dev) |
535 | { | 399 | { |
@@ -646,12 +510,19 @@ DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | M | |||
646 | *DB: "DirectBurn" | 510 | *DB: "DirectBurn" |
647 | */ | 511 | */ |
648 | 512 | ||
649 | static struct blackbird_dnr default_dnr_params = { | 513 | static void blackbird_codec_settings(struct cx8802_dev *dev) |
650 | .mode = BLACKBIRD_DNR_BITS_MANUAL, | 514 | { |
651 | .type = BLACKBIRD_MEDIAN_FILTER_DISABLED, | 515 | /* assign frame size */ |
652 | .spatial = 0, | 516 | blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, |
653 | .temporal = 0 | 517 | dev->height, dev->width); |
654 | }; | 518 | |
519 | dev->params.width = dev->width; | ||
520 | dev->params.height = dev->height; | ||
521 | dev->params.is_50hz = (dev->core->tvnorm->id & V4L2_STD_625_50) != 0; | ||
522 | |||
523 | cx2341x_update(dev, blackbird_mbox_func, NULL, &dev->params); | ||
524 | } | ||
525 | |||
655 | static struct v4l2_mpeg_compression default_mpeg_params = { | 526 | static struct v4l2_mpeg_compression default_mpeg_params = { |
656 | .st_type = V4L2_MPEG_PS_2, | 527 | .st_type = V4L2_MPEG_PS_2, |
657 | .st_bitrate = { | 528 | .st_bitrate = { |
@@ -672,7 +543,7 @@ static struct v4l2_mpeg_compression default_mpeg_params = { | |||
672 | .target = 224, | 543 | .target = 224, |
673 | .max = 224 | 544 | .max = 224 |
674 | }, | 545 | }, |
675 | .au_sample_rate = 44100, | 546 | .au_sample_rate = 48000, |
676 | .au_pesid = 0, | 547 | .au_pesid = 0, |
677 | .vi_type = V4L2_MPEG_VI_2, | 548 | .vi_type = V4L2_MPEG_VI_2, |
678 | .vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3, | 549 | .vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3, |
@@ -683,524 +554,13 @@ static struct v4l2_mpeg_compression default_mpeg_params = { | |||
683 | .max = 6000 | 554 | .max = 6000 |
684 | }, | 555 | }, |
685 | .vi_frame_rate = 25, | 556 | .vi_frame_rate = 25, |
686 | .vi_frames_per_gop = 15, | 557 | .vi_frames_per_gop = 12, |
687 | .vi_bframes_count = 2, | 558 | .vi_bframes_count = 2, |
688 | .vi_pesid = 0, | 559 | .vi_pesid = 0, |
689 | .closed_gops = 0, | 560 | .closed_gops = 1, |
690 | .pulldown = 0 | 561 | .pulldown = 0 |
691 | }; | 562 | }; |
692 | 563 | ||
693 | static enum blackbird_stream_type mpeg_stream_types[] = { | ||
694 | [V4L2_MPEG_SS_1] = BLACKBIRD_STREAM_MPEG1, | ||
695 | [V4L2_MPEG_PS_2] = BLACKBIRD_STREAM_PROGRAM, | ||
696 | [V4L2_MPEG_TS_2] = BLACKBIRD_STREAM_TRANSPORT, | ||
697 | [V4L2_MPEG_PS_DVD] = BLACKBIRD_STREAM_DVD, | ||
698 | }; | ||
699 | static enum blackbird_aspect_ratio mpeg_stream_ratios[] = { | ||
700 | [V4L2_MPEG_ASPECT_SQUARE] = BLACKBIRD_ASPECT_RATIO_1_1_SQUARE, | ||
701 | [V4L2_MPEG_ASPECT_4_3] = BLACKBIRD_ASPECT_RATIO_4_3, | ||
702 | [V4L2_MPEG_ASPECT_16_9] = BLACKBIRD_ASPECT_RATIO_16_9, | ||
703 | [V4L2_MPEG_ASPECT_1_221] = BLACKBIRD_ASPECT_RATIO_221_100, | ||
704 | }; | ||
705 | static enum blackbird_video_bitrate_type mpeg_video_bitrates[] = { | ||
706 | [V4L2_BITRATE_NONE] = BLACKBIRD_VIDEO_CBR, | ||
707 | [V4L2_BITRATE_CBR] = BLACKBIRD_VIDEO_CBR, | ||
708 | [V4L2_BITRATE_VBR] = BLACKBIRD_VIDEO_VBR, | ||
709 | }; | ||
710 | /* find the best layer I/II bitrate to fit a given numeric value */ | ||
711 | struct bitrate_bits { | ||
712 | u32 bits; /* layer bits for the best fit */ | ||
713 | u32 rate; /* actual numeric value for the layer best fit */ | ||
714 | }; | ||
715 | struct bitrate_approximation { | ||
716 | u32 target; /* numeric value of the rate we want */ | ||
717 | struct bitrate_bits layer[2]; | ||
718 | }; | ||
719 | static struct bitrate_approximation mpeg_audio_bitrates[] = { | ||
720 | /* target layer[0].bits layer[0].rate layer[1].bits layer[1].rate */ | ||
721 | { 0, { { 0, 0, }, { 0, 0, }, }, }, | ||
722 | { 32, { { BLACKBIRD_AUDIO_BITS_LAYER_1_32 , 32, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_32 , 32, }, }, }, | ||
723 | { 48, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_48 , 48, }, }, }, | ||
724 | { 56, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_56 , 56, }, }, }, | ||
725 | { 64, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_64 , 64, }, }, }, | ||
726 | { 80, { { BLACKBIRD_AUDIO_BITS_LAYER_1_96 , 96, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_80 , 80, }, }, }, | ||
727 | { 96, { { BLACKBIRD_AUDIO_BITS_LAYER_1_96 , 96, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_96 , 96, }, }, }, | ||
728 | { 112, { { BLACKBIRD_AUDIO_BITS_LAYER_1_128, 128, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_112, 112, }, }, }, | ||
729 | { 128, { { BLACKBIRD_AUDIO_BITS_LAYER_1_128, 128, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_128, 128, }, }, }, | ||
730 | { 160, { { BLACKBIRD_AUDIO_BITS_LAYER_1_160, 160, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_160, 160, }, }, }, | ||
731 | { 192, { { BLACKBIRD_AUDIO_BITS_LAYER_1_192, 192, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_192, 192, }, }, }, | ||
732 | { 224, { { BLACKBIRD_AUDIO_BITS_LAYER_1_224, 224, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_224, 224, }, }, }, | ||
733 | { 256, { { BLACKBIRD_AUDIO_BITS_LAYER_1_256, 256, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_256, 256, }, }, }, | ||
734 | { 288, { { BLACKBIRD_AUDIO_BITS_LAYER_1_288, 288, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_320, 320, }, }, }, | ||
735 | { 320, { { BLACKBIRD_AUDIO_BITS_LAYER_1_320, 320, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_320, 320, }, }, }, | ||
736 | { 352, { { BLACKBIRD_AUDIO_BITS_LAYER_1_352, 352, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, | ||
737 | { 384, { { BLACKBIRD_AUDIO_BITS_LAYER_1_384, 384, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, | ||
738 | { 416, { { BLACKBIRD_AUDIO_BITS_LAYER_1_416, 416, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, | ||
739 | { 448, { { BLACKBIRD_AUDIO_BITS_LAYER_1_448, 448, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, | ||
740 | }; | ||
741 | static const int BITRATES_SIZE = ARRAY_SIZE(mpeg_audio_bitrates); | ||
742 | |||
743 | static void blackbird_set_default_params(struct cx8802_dev *dev) | ||
744 | { | ||
745 | struct v4l2_mpeg_compression *params = &dev->params; | ||
746 | u32 au_params; | ||
747 | |||
748 | /* assign stream type */ | ||
749 | if( params->st_type >= ARRAY_SIZE(mpeg_stream_types) ) | ||
750 | params->st_type = V4L2_MPEG_PS_2; | ||
751 | if( params->st_type == V4L2_MPEG_SS_1 ) | ||
752 | params->vi_type = V4L2_MPEG_VI_1; | ||
753 | else | ||
754 | params->vi_type = V4L2_MPEG_VI_2; | ||
755 | blackbird_api_cmd(dev, CX2341X_ENC_SET_STREAM_TYPE, 1, 0, mpeg_stream_types[params->st_type]); | ||
756 | |||
757 | /* assign framerate */ | ||
758 | if( params->vi_frame_rate <= 25 ) | ||
759 | { | ||
760 | params->vi_frame_rate = 25; | ||
761 | blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_PAL_25); | ||
762 | } | ||
763 | else | ||
764 | { | ||
765 | params->vi_frame_rate = 30; | ||
766 | blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_NTSC_30); | ||
767 | } | ||
768 | |||
769 | /* assign aspect ratio */ | ||
770 | if( params->vi_aspect_ratio >= ARRAY_SIZE(mpeg_stream_ratios) ) | ||
771 | params->vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3; | ||
772 | blackbird_api_cmd(dev, CX2341X_ENC_SET_ASPECT_RATIO, 1, 0, mpeg_stream_ratios[params->vi_aspect_ratio]); | ||
773 | |||
774 | /* assign gop properties */ | ||
775 | blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_PROPERTIES, 2, 0, params->vi_frames_per_gop, params->vi_bframes_count+1); | ||
776 | |||
777 | /* assign gop closure */ | ||
778 | blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_CLOSURE, 1, 0, params->closed_gops); | ||
779 | |||
780 | /* assign 3 2 pulldown */ | ||
781 | blackbird_api_cmd(dev, CX2341X_ENC_SET_3_2_PULLDOWN, 1, 0, params->pulldown); | ||
782 | |||
783 | /* make sure the params are within bounds */ | ||
784 | if( params->st_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) | ||
785 | params->vi_bitrate.mode = V4L2_BITRATE_NONE; | ||
786 | if( params->vi_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) | ||
787 | params->vi_bitrate.mode = V4L2_BITRATE_NONE; | ||
788 | if( params->au_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) | ||
789 | params->au_bitrate.mode = V4L2_BITRATE_NONE; | ||
790 | |||
791 | /* assign audio properties */ | ||
792 | /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */ | ||
793 | au_params = BLACKBIRD_AUDIO_BITS_STEREO | | ||
794 | /* BLACKBIRD_AUDIO_BITS_BOUND_4 | */ | ||
795 | BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE | | ||
796 | BLACKBIRD_AUDIO_BITS_CRC_OFF | | ||
797 | BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF | | ||
798 | BLACKBIRD_AUDIO_BITS_COPY | | ||
799 | 0; | ||
800 | if( params->au_sample_rate <= 32000 ) | ||
801 | { | ||
802 | params->au_sample_rate = 32000; | ||
803 | au_params |= BLACKBIRD_AUDIO_BITS_32000HZ; | ||
804 | } | ||
805 | else if( params->au_sample_rate <= 44100 ) | ||
806 | { | ||
807 | params->au_sample_rate = 44100; | ||
808 | au_params |= BLACKBIRD_AUDIO_BITS_44100HZ; | ||
809 | } | ||
810 | else | ||
811 | { | ||
812 | params->au_sample_rate = 48000; | ||
813 | au_params |= BLACKBIRD_AUDIO_BITS_48000HZ; | ||
814 | } | ||
815 | if( params->au_type == V4L2_MPEG_AU_2_I ) | ||
816 | { | ||
817 | au_params |= BLACKBIRD_AUDIO_BITS_LAYER_1; | ||
818 | } | ||
819 | else | ||
820 | { | ||
821 | /* TODO: try to handle the other formats more gracefully */ | ||
822 | params->au_type = V4L2_MPEG_AU_2_II; | ||
823 | au_params |= BLACKBIRD_AUDIO_BITS_LAYER_2; | ||
824 | } | ||
825 | if( params->au_bitrate.mode ) | ||
826 | { | ||
827 | int layer; | ||
828 | |||
829 | if( params->au_bitrate.mode == V4L2_BITRATE_CBR ) | ||
830 | params->au_bitrate.max = params->vi_bitrate.target; | ||
831 | else | ||
832 | params->au_bitrate.target = params->vi_bitrate.max; | ||
833 | |||
834 | layer = params->au_type; | ||
835 | if( params->au_bitrate.target == 0 ) | ||
836 | { | ||
837 | /* TODO: use the minimum possible bitrate instead of 0 ? */ | ||
838 | au_params |= 0; | ||
839 | } | ||
840 | else if( params->au_bitrate.target >= | ||
841 | mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate ) | ||
842 | { | ||
843 | /* clamp the bitrate to the max supported by the standard */ | ||
844 | params->au_bitrate.target = mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate; | ||
845 | params->au_bitrate.max = params->au_bitrate.target; | ||
846 | au_params |= mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].bits; | ||
847 | } | ||
848 | else | ||
849 | { | ||
850 | /* round up to the nearest supported bitrate */ | ||
851 | int i; | ||
852 | for(i = 1; i < BITRATES_SIZE; i++) | ||
853 | { | ||
854 | if( params->au_bitrate.target > mpeg_audio_bitrates[i-1].layer[layer].rate && | ||
855 | params->au_bitrate.target <= mpeg_audio_bitrates[i].layer[layer].rate ) | ||
856 | { | ||
857 | params->au_bitrate.target = mpeg_audio_bitrates[i].layer[layer].rate; | ||
858 | params->au_bitrate.max = params->au_bitrate.target; | ||
859 | au_params |= mpeg_audio_bitrates[i].layer[layer].bits; | ||
860 | break; | ||
861 | } | ||
862 | } | ||
863 | } | ||
864 | } | ||
865 | else | ||
866 | { | ||
867 | /* TODO: ??? */ | ||
868 | params->au_bitrate.target = params->au_bitrate.max = 0; | ||
869 | au_params |= 0; | ||
870 | } | ||
871 | blackbird_api_cmd(dev, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, 0, au_params ); | ||
872 | |||
873 | /* assign bitrates */ | ||
874 | if( params->vi_bitrate.mode ) | ||
875 | { | ||
876 | /* bitrate is set, let's figure out the cbr/vbr mess */ | ||
877 | if( params->vi_bitrate.max < params->vi_bitrate.target ) | ||
878 | { | ||
879 | if( params->vi_bitrate.mode == V4L2_BITRATE_CBR ) | ||
880 | params->vi_bitrate.max = params->vi_bitrate.target; | ||
881 | else | ||
882 | params->vi_bitrate.target = params->vi_bitrate.max; | ||
883 | } | ||
884 | } | ||
885 | else | ||
886 | { | ||
887 | if( params->st_bitrate.max < params->st_bitrate.target ) | ||
888 | { | ||
889 | if( params->st_bitrate.mode == V4L2_BITRATE_VBR ) | ||
890 | params->st_bitrate.target = params->st_bitrate.max; | ||
891 | else | ||
892 | params->st_bitrate.max = params->st_bitrate.target; | ||
893 | } | ||
894 | /* calculate vi_bitrate = st_bitrate - au_bitrate */ | ||
895 | params->vi_bitrate.max = params->st_bitrate.max - params->au_bitrate.max; | ||
896 | params->vi_bitrate.target = params->st_bitrate.target - params->au_bitrate.target; | ||
897 | } | ||
898 | blackbird_api_cmd(dev, CX2341X_ENC_SET_BIT_RATE, 4, 0, | ||
899 | mpeg_video_bitrates[params->vi_bitrate.mode], | ||
900 | params->vi_bitrate.target * 1000, /* kbps -> bps */ | ||
901 | params->vi_bitrate.max * 1000 / BLACKBIRD_PEAK_RATE_DIVISOR, /* peak/400 */ | ||
902 | BLACKBIRD_MUX_RATE_DEFAULT /*, 0x70*/); /* encoding buffer, ckennedy */ | ||
903 | |||
904 | /* TODO: implement the stream ID stuff: | ||
905 | ts_pid_pmt, ts_pid_audio, ts_pid_video, ts_pid_pcr, | ||
906 | ps_size, au_pesid, vi_pesid | ||
907 | */ | ||
908 | } | ||
909 | #define CHECK_PARAM( name ) ( dev->params.name != params->name ) | ||
910 | #define IF_PARAM( name ) if( CHECK_PARAM( name ) ) | ||
911 | #define UPDATE_PARAM( name ) dev->params.name = params->name | ||
912 | void blackbird_set_params(struct cx8802_dev *dev, struct v4l2_mpeg_compression *params) | ||
913 | { | ||
914 | u32 au_params; | ||
915 | |||
916 | /* assign stream type */ | ||
917 | if( params->st_type >= ARRAY_SIZE(mpeg_stream_types) ) | ||
918 | params->st_type = V4L2_MPEG_PS_2; | ||
919 | if( params->st_type == V4L2_MPEG_SS_1 ) | ||
920 | params->vi_type = V4L2_MPEG_VI_1; | ||
921 | else | ||
922 | params->vi_type = V4L2_MPEG_VI_2; | ||
923 | if( CHECK_PARAM( st_type ) || CHECK_PARAM( vi_type ) ) | ||
924 | { | ||
925 | UPDATE_PARAM( st_type ); | ||
926 | UPDATE_PARAM( vi_type ); | ||
927 | blackbird_api_cmd(dev, CX2341X_ENC_SET_STREAM_TYPE, 1, 0, mpeg_stream_types[params->st_type]); | ||
928 | } | ||
929 | |||
930 | /* assign framerate */ | ||
931 | if( params->vi_frame_rate <= 25 ) | ||
932 | params->vi_frame_rate = 25; | ||
933 | else | ||
934 | params->vi_frame_rate = 30; | ||
935 | IF_PARAM( vi_frame_rate ) | ||
936 | { | ||
937 | UPDATE_PARAM( vi_frame_rate ); | ||
938 | if( params->vi_frame_rate == 25 ) | ||
939 | blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_PAL_25); | ||
940 | else | ||
941 | blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_NTSC_30); | ||
942 | } | ||
943 | |||
944 | /* assign aspect ratio */ | ||
945 | if( params->vi_aspect_ratio >= ARRAY_SIZE(mpeg_stream_ratios) ) | ||
946 | params->vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3; | ||
947 | IF_PARAM( vi_aspect_ratio ) | ||
948 | { | ||
949 | UPDATE_PARAM( vi_aspect_ratio ); | ||
950 | blackbird_api_cmd(dev, CX2341X_ENC_SET_ASPECT_RATIO, 1, 0, mpeg_stream_ratios[params->vi_aspect_ratio]); | ||
951 | } | ||
952 | |||
953 | /* assign gop properties */ | ||
954 | if( CHECK_PARAM( vi_frames_per_gop ) || CHECK_PARAM( vi_bframes_count ) ) | ||
955 | { | ||
956 | UPDATE_PARAM( vi_frames_per_gop ); | ||
957 | UPDATE_PARAM( vi_bframes_count ); | ||
958 | blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_PROPERTIES, 2, 0, params->vi_frames_per_gop, params->vi_bframes_count+1); | ||
959 | } | ||
960 | |||
961 | /* assign gop closure */ | ||
962 | IF_PARAM( closed_gops ) | ||
963 | { | ||
964 | UPDATE_PARAM( closed_gops ); | ||
965 | blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_CLOSURE, 1, 0, params->closed_gops); | ||
966 | } | ||
967 | |||
968 | /* assign 3 2 pulldown */ | ||
969 | IF_PARAM( pulldown ) | ||
970 | { | ||
971 | UPDATE_PARAM( pulldown ); | ||
972 | blackbird_api_cmd(dev, CX2341X_ENC_SET_3_2_PULLDOWN, 1, 0, params->pulldown); | ||
973 | } | ||
974 | |||
975 | /* make sure the params are within bounds */ | ||
976 | if( params->st_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) | ||
977 | params->vi_bitrate.mode = V4L2_BITRATE_NONE; | ||
978 | if( params->vi_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) | ||
979 | params->vi_bitrate.mode = V4L2_BITRATE_NONE; | ||
980 | if( params->au_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) | ||
981 | params->au_bitrate.mode = V4L2_BITRATE_NONE; | ||
982 | |||
983 | /* assign audio properties */ | ||
984 | /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */ | ||
985 | au_params = BLACKBIRD_AUDIO_BITS_STEREO | | ||
986 | /* BLACKBIRD_AUDIO_BITS_BOUND_4 | */ | ||
987 | BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE | | ||
988 | BLACKBIRD_AUDIO_BITS_CRC_OFF | | ||
989 | BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF | | ||
990 | BLACKBIRD_AUDIO_BITS_COPY | | ||
991 | 0; | ||
992 | if( params->au_sample_rate < 32000 ) | ||
993 | { | ||
994 | params->au_sample_rate = 32000; | ||
995 | au_params |= BLACKBIRD_AUDIO_BITS_32000HZ; | ||
996 | } | ||
997 | else if( params->au_sample_rate < 44100 ) | ||
998 | { | ||
999 | params->au_sample_rate = 44100; | ||
1000 | au_params |= BLACKBIRD_AUDIO_BITS_44100HZ; | ||
1001 | } | ||
1002 | else | ||
1003 | { | ||
1004 | params->au_sample_rate = 48000; | ||
1005 | au_params |= BLACKBIRD_AUDIO_BITS_48000HZ; | ||
1006 | } | ||
1007 | if( params->au_type == V4L2_MPEG_AU_2_I ) | ||
1008 | { | ||
1009 | au_params |= BLACKBIRD_AUDIO_BITS_LAYER_1; | ||
1010 | } | ||
1011 | else | ||
1012 | { | ||
1013 | /* TODO: try to handle the other formats more gracefully */ | ||
1014 | params->au_type = V4L2_MPEG_AU_2_II; | ||
1015 | au_params |= BLACKBIRD_AUDIO_BITS_LAYER_2; | ||
1016 | } | ||
1017 | if( params->au_bitrate.mode ) | ||
1018 | { | ||
1019 | int layer; | ||
1020 | |||
1021 | if( params->au_bitrate.mode == V4L2_BITRATE_CBR ) | ||
1022 | params->au_bitrate.max = params->vi_bitrate.target; | ||
1023 | else | ||
1024 | params->au_bitrate.target = params->vi_bitrate.max; | ||
1025 | |||
1026 | layer = params->au_type; | ||
1027 | if( params->au_bitrate.target == 0 ) | ||
1028 | { | ||
1029 | /* TODO: use the minimum possible bitrate instead of 0 ? */ | ||
1030 | au_params |= 0; | ||
1031 | } | ||
1032 | else if( params->au_bitrate.target >= | ||
1033 | mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate ) | ||
1034 | { | ||
1035 | /* clamp the bitrate to the max supported by the standard */ | ||
1036 | params->au_bitrate.target = mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate; | ||
1037 | params->au_bitrate.max = params->au_bitrate.target; | ||
1038 | au_params |= mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].bits; | ||
1039 | } | ||
1040 | else | ||
1041 | { | ||
1042 | /* round up to the nearest supported bitrate */ | ||
1043 | int i; | ||
1044 | for(i = 1; i < BITRATES_SIZE; i++) | ||
1045 | { | ||
1046 | if( params->au_bitrate.target > mpeg_audio_bitrates[i-1].layer[layer].rate && | ||
1047 | params->au_bitrate.target <= mpeg_audio_bitrates[i].layer[layer].rate ) | ||
1048 | { | ||
1049 | params->au_bitrate.target = mpeg_audio_bitrates[i].layer[layer].rate; | ||
1050 | params->au_bitrate.max = params->au_bitrate.target; | ||
1051 | au_params |= mpeg_audio_bitrates[i].layer[layer].bits; | ||
1052 | break; | ||
1053 | } | ||
1054 | } | ||
1055 | } | ||
1056 | } | ||
1057 | else | ||
1058 | { | ||
1059 | /* TODO: ??? */ | ||
1060 | params->au_bitrate.target = params->au_bitrate.max = 0; | ||
1061 | au_params |= 0; | ||
1062 | } | ||
1063 | if( CHECK_PARAM( au_type ) || CHECK_PARAM( au_sample_rate ) | ||
1064 | || CHECK_PARAM( au_bitrate.mode ) || CHECK_PARAM( au_bitrate.max ) | ||
1065 | || CHECK_PARAM( au_bitrate.target ) | ||
1066 | ) | ||
1067 | { | ||
1068 | UPDATE_PARAM( au_type ); | ||
1069 | UPDATE_PARAM( au_sample_rate ); | ||
1070 | UPDATE_PARAM( au_bitrate ); | ||
1071 | blackbird_api_cmd(dev, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, 0, au_params ); | ||
1072 | } | ||
1073 | |||
1074 | /* assign bitrates */ | ||
1075 | if( params->vi_bitrate.mode ) | ||
1076 | { | ||
1077 | /* bitrate is set, let's figure out the cbr/vbr mess */ | ||
1078 | if( params->vi_bitrate.max < params->vi_bitrate.target ) | ||
1079 | { | ||
1080 | if( params->vi_bitrate.mode == V4L2_BITRATE_CBR ) | ||
1081 | params->vi_bitrate.max = params->vi_bitrate.target; | ||
1082 | else | ||
1083 | params->vi_bitrate.target = params->vi_bitrate.max; | ||
1084 | } | ||
1085 | } | ||
1086 | else | ||
1087 | { | ||
1088 | if( params->st_bitrate.max < params->st_bitrate.target ) | ||
1089 | { | ||
1090 | if( params->st_bitrate.mode == V4L2_BITRATE_VBR ) | ||
1091 | params->st_bitrate.target = params->st_bitrate.max; | ||
1092 | else | ||
1093 | params->st_bitrate.max = params->st_bitrate.target; | ||
1094 | } | ||
1095 | /* calculate vi_bitrate = st_bitrate - au_bitrate */ | ||
1096 | params->vi_bitrate.max = params->st_bitrate.max - params->au_bitrate.max; | ||
1097 | params->vi_bitrate.target = params->st_bitrate.target - params->au_bitrate.target; | ||
1098 | } | ||
1099 | UPDATE_PARAM( st_bitrate ); | ||
1100 | if( CHECK_PARAM( vi_bitrate.mode ) || CHECK_PARAM( vi_bitrate.max ) | ||
1101 | || CHECK_PARAM( vi_bitrate.target ) | ||
1102 | ) | ||
1103 | { | ||
1104 | UPDATE_PARAM( vi_bitrate ); | ||
1105 | blackbird_api_cmd(dev, CX2341X_ENC_SET_BIT_RATE, 4, 0, | ||
1106 | mpeg_video_bitrates[params->vi_bitrate.mode], | ||
1107 | params->vi_bitrate.target * 1000, /* kbps -> bps */ | ||
1108 | params->vi_bitrate.max * 1000 / BLACKBIRD_PEAK_RATE_DIVISOR, /* peak/400 */ | ||
1109 | BLACKBIRD_MUX_RATE_DEFAULT /*, 0x70*/); /* encoding buffer, ckennedy */ | ||
1110 | } | ||
1111 | |||
1112 | /* TODO: implement the stream ID stuff: | ||
1113 | ts_pid_pmt, ts_pid_audio, ts_pid_video, ts_pid_pcr, | ||
1114 | ps_size, au_pesid, vi_pesid | ||
1115 | */ | ||
1116 | UPDATE_PARAM( ts_pid_pmt ); | ||
1117 | UPDATE_PARAM( ts_pid_audio ); | ||
1118 | UPDATE_PARAM( ts_pid_video ); | ||
1119 | UPDATE_PARAM( ts_pid_pcr ); | ||
1120 | UPDATE_PARAM( ps_size ); | ||
1121 | UPDATE_PARAM( au_pesid ); | ||
1122 | UPDATE_PARAM( vi_pesid ); | ||
1123 | } | ||
1124 | |||
1125 | static void blackbird_set_default_dnr_params(struct cx8802_dev *dev) | ||
1126 | { | ||
1127 | /* assign dnr filter mode */ | ||
1128 | if( dev->dnr_params.mode > BLACKBIRD_DNR_BITS_AUTO ) | ||
1129 | dev->dnr_params.mode = BLACKBIRD_DNR_BITS_MANUAL; | ||
1130 | if( dev->dnr_params.type > BLACKBIRD_MEDIAN_FILTER_DIAGONAL ) | ||
1131 | dev->dnr_params.type = BLACKBIRD_MEDIAN_FILTER_DISABLED; | ||
1132 | blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, 0, | ||
1133 | dev->dnr_params.mode, | ||
1134 | dev->dnr_params.type | ||
1135 | ); | ||
1136 | |||
1137 | /* assign dnr filter props*/ | ||
1138 | if( dev->dnr_params.spatial > 15 ) | ||
1139 | dev->dnr_params.spatial = 15; | ||
1140 | if( dev->dnr_params.temporal > 31 ) | ||
1141 | dev->dnr_params.temporal = 31; | ||
1142 | blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 0, | ||
1143 | dev->dnr_params.spatial, | ||
1144 | dev->dnr_params.temporal | ||
1145 | ); | ||
1146 | } | ||
1147 | #define CHECK_DNR_PARAM( name ) ( dev->dnr_params.name != dnr_params->name ) | ||
1148 | #define UPDATE_DNR_PARAM( name ) dev->dnr_params.name = dnr_params->name | ||
1149 | void blackbird_set_dnr_params(struct cx8802_dev *dev, struct blackbird_dnr* dnr_params) | ||
1150 | { | ||
1151 | /* assign dnr filter mode */ | ||
1152 | /* clamp values */ | ||
1153 | if( dnr_params->mode > BLACKBIRD_DNR_BITS_AUTO ) | ||
1154 | dnr_params->mode = BLACKBIRD_DNR_BITS_MANUAL; | ||
1155 | if( dnr_params->type > BLACKBIRD_MEDIAN_FILTER_DIAGONAL ) | ||
1156 | dnr_params->type = BLACKBIRD_MEDIAN_FILTER_DISABLED; | ||
1157 | /* check if the params actually changed */ | ||
1158 | if( CHECK_DNR_PARAM( mode ) || CHECK_DNR_PARAM( type ) ) | ||
1159 | { | ||
1160 | UPDATE_DNR_PARAM( mode ); | ||
1161 | UPDATE_DNR_PARAM( type ); | ||
1162 | blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, 0, dnr_params->mode, dnr_params->type); | ||
1163 | } | ||
1164 | |||
1165 | /* assign dnr filter props*/ | ||
1166 | if( dnr_params->spatial > 15 ) | ||
1167 | dnr_params->spatial = 15; | ||
1168 | if( dnr_params->temporal > 31 ) | ||
1169 | dnr_params->temporal = 31; | ||
1170 | if( CHECK_DNR_PARAM( spatial ) || CHECK_DNR_PARAM( temporal ) ) | ||
1171 | { | ||
1172 | UPDATE_DNR_PARAM( spatial ); | ||
1173 | UPDATE_DNR_PARAM( temporal ); | ||
1174 | blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 0, dnr_params->spatial, dnr_params->temporal); | ||
1175 | } | ||
1176 | } | ||
1177 | |||
1178 | static void blackbird_codec_settings(struct cx8802_dev *dev) | ||
1179 | { | ||
1180 | |||
1181 | /* assign output port */ | ||
1182 | blackbird_api_cmd(dev, CX2341X_ENC_SET_OUTPUT_PORT, 1, 0, BLACKBIRD_OUTPUT_PORT_STREAMING); /* Host */ | ||
1183 | |||
1184 | /* assign frame size */ | ||
1185 | blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, | ||
1186 | dev->height, dev->width); | ||
1187 | |||
1188 | /* assign coring levels (luma_h, luma_l, chroma_h, chroma_l) */ | ||
1189 | blackbird_api_cmd(dev, CX2341X_ENC_SET_CORING_LEVELS, 4, 0, 0, 255, 0, 255); | ||
1190 | |||
1191 | /* assign spatial filter type: luma_t: horiz_only, chroma_t: horiz_only */ | ||
1192 | blackbird_api_cmd(dev, CX2341X_ENC_SET_SPATIAL_FILTER_TYPE, 2, 0, | ||
1193 | BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ, | ||
1194 | BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ | ||
1195 | ); | ||
1196 | |||
1197 | /* assign frame drop rate */ | ||
1198 | /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_FRAME_DROP_RATE, 1, 0, 0); */ | ||
1199 | |||
1200 | blackbird_set_default_params(dev); | ||
1201 | blackbird_set_default_dnr_params(dev); | ||
1202 | } | ||
1203 | |||
1204 | static int blackbird_initialize_codec(struct cx8802_dev *dev) | 564 | static int blackbird_initialize_codec(struct cx8802_dev *dev) |
1205 | { | 565 | { |
1206 | struct cx88_core *core = dev->core; | 566 | struct cx88_core *core = dev->core; |
@@ -1445,15 +805,35 @@ static int mpeg_do_ioctl(struct inode *inode, struct file *file, | |||
1445 | { | 805 | { |
1446 | struct v4l2_mpeg_compression *f = arg; | 806 | struct v4l2_mpeg_compression *f = arg; |
1447 | 807 | ||
1448 | memcpy(f,&dev->params,sizeof(*f)); | 808 | memcpy(f,&default_mpeg_params,sizeof(*f)); |
1449 | return 0; | 809 | return 0; |
1450 | } | 810 | } |
1451 | case VIDIOC_S_MPEGCOMP: | 811 | case VIDIOC_S_MPEGCOMP: |
812 | return 0; | ||
813 | case VIDIOC_G_EXT_CTRLS: | ||
1452 | { | 814 | { |
1453 | struct v4l2_mpeg_compression *f = arg; | 815 | struct v4l2_ext_controls *f = arg; |
1454 | 816 | ||
1455 | blackbird_set_params(dev, f); | 817 | if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) |
1456 | return 0; | 818 | return -EINVAL; |
819 | return cx2341x_ext_ctrls(&dev->params, f, cmd); | ||
820 | } | ||
821 | case VIDIOC_S_EXT_CTRLS: | ||
822 | case VIDIOC_TRY_EXT_CTRLS: | ||
823 | { | ||
824 | struct v4l2_ext_controls *f = arg; | ||
825 | struct cx2341x_mpeg_params p; | ||
826 | int err; | ||
827 | |||
828 | if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) | ||
829 | return -EINVAL; | ||
830 | p = dev->params; | ||
831 | err = cx2341x_ext_ctrls(&p, f, cmd); | ||
832 | if (err == 0 && cmd == VIDIOC_S_EXT_CTRLS) { | ||
833 | err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p); | ||
834 | dev->params = p; | ||
835 | } | ||
836 | return err; | ||
1457 | } | 837 | } |
1458 | case VIDIOC_S_FREQUENCY: | 838 | case VIDIOC_S_FREQUENCY: |
1459 | { | 839 | { |
@@ -1658,26 +1038,21 @@ static int __devinit blackbird_probe(struct pci_dev *pci_dev, | |||
1658 | dev->core = core; | 1038 | dev->core = core; |
1659 | dev->width = 720; | 1039 | dev->width = 720; |
1660 | dev->height = 576; | 1040 | dev->height = 576; |
1661 | memcpy(&dev->params,&default_mpeg_params,sizeof(default_mpeg_params)); | 1041 | cx2341x_fill_defaults(&dev->params); |
1662 | memcpy(&dev->dnr_params,&default_dnr_params,sizeof(default_dnr_params)); | ||
1663 | 1042 | ||
1664 | switch (core->board) { | 1043 | switch (core->board) { |
1665 | case CX88_BOARD_HAUPPAUGE_ROSLYN: | 1044 | case CX88_BOARD_HAUPPAUGE_ROSLYN: |
1666 | if (core->tuner_formats & V4L2_STD_525_60) { | 1045 | if (core->tuner_formats & V4L2_STD_525_60) { |
1667 | dev->height = 480; | 1046 | dev->height = 480; |
1668 | dev->params.vi_frame_rate = 30; | ||
1669 | } else { | 1047 | } else { |
1670 | dev->height = 576; | 1048 | dev->height = 576; |
1671 | dev->params.vi_frame_rate = 25; | ||
1672 | } | 1049 | } |
1673 | break; | 1050 | break; |
1674 | case CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT: | 1051 | case CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT: |
1675 | if (core->tvnorm->id & V4L2_STD_525_60) { | 1052 | if (core->tvnorm->id & V4L2_STD_525_60) { |
1676 | dev->height = 480; | 1053 | dev->height = 480; |
1677 | dev->params.vi_frame_rate = 30; | ||
1678 | } else { | 1054 | } else { |
1679 | dev->height = 576; | 1055 | dev->height = 576; |
1680 | dev->params.vi_frame_rate = 25; | ||
1681 | } | 1056 | } |
1682 | break; | 1057 | break; |
1683 | } | 1058 | } |
@@ -1765,8 +1140,6 @@ module_exit(blackbird_fini); | |||
1765 | 1140 | ||
1766 | EXPORT_SYMBOL(cx88_ioctl_hook); | 1141 | EXPORT_SYMBOL(cx88_ioctl_hook); |
1767 | EXPORT_SYMBOL(cx88_ioctl_translator); | 1142 | EXPORT_SYMBOL(cx88_ioctl_translator); |
1768 | EXPORT_SYMBOL(blackbird_set_params); | ||
1769 | EXPORT_SYMBOL(blackbird_set_dnr_params); | ||
1770 | 1143 | ||
1771 | /* ----------------------------------------------------------- */ | 1144 | /* ----------------------------------------------------------- */ |
1772 | /* | 1145 | /* |
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h index f27d4df5b30e..dc7bc35f18f4 100644 --- a/drivers/media/video/cx88/cx88.h +++ b/drivers/media/video/cx88/cx88.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #include <media/tuner.h> | 29 | #include <media/tuner.h> |
30 | #include <media/tveeprom.h> | 30 | #include <media/tveeprom.h> |
31 | #include <media/video-buf.h> | 31 | #include <media/video-buf.h> |
32 | #include <media/cx2341x.h> | ||
32 | #include <media/video-buf-dvb.h> | 33 | #include <media/video-buf-dvb.h> |
33 | 34 | ||
34 | #include "btcx-risc.h" | 35 | #include "btcx-risc.h" |
@@ -398,14 +399,6 @@ struct cx8802_suspend_state { | |||
398 | int disabled; | 399 | int disabled; |
399 | }; | 400 | }; |
400 | 401 | ||
401 | /* TODO: move this to struct v4l2_mpeg_compression ? */ | ||
402 | struct blackbird_dnr { | ||
403 | u32 mode; | ||
404 | u32 type; | ||
405 | u32 spatial; | ||
406 | u32 temporal; | ||
407 | }; | ||
408 | |||
409 | struct cx8802_dev { | 402 | struct cx8802_dev { |
410 | struct cx88_core *core; | 403 | struct cx88_core *core; |
411 | spinlock_t slock; | 404 | spinlock_t slock; |
@@ -439,8 +432,7 @@ struct cx8802_dev { | |||
439 | unsigned char ts_gen_cntrl; | 432 | unsigned char ts_gen_cntrl; |
440 | 433 | ||
441 | /* mpeg params */ | 434 | /* mpeg params */ |
442 | struct v4l2_mpeg_compression params; | 435 | struct cx2341x_mpeg_params params; |
443 | struct blackbird_dnr dnr_params; | ||
444 | }; | 436 | }; |
445 | 437 | ||
446 | /* ----------------------------------------------------------- */ | 438 | /* ----------------------------------------------------------- */ |
@@ -605,10 +597,6 @@ extern int cx88_do_ioctl(struct inode *inode, struct file *file, int radio, | |||
605 | extern int (*cx88_ioctl_hook)(struct inode *inode, struct file *file, | 597 | extern int (*cx88_ioctl_hook)(struct inode *inode, struct file *file, |
606 | unsigned int cmd, void *arg); | 598 | unsigned int cmd, void *arg); |
607 | extern unsigned int (*cx88_ioctl_translator)(unsigned int cmd); | 599 | extern unsigned int (*cx88_ioctl_translator)(unsigned int cmd); |
608 | void blackbird_set_params(struct cx8802_dev *dev, | ||
609 | struct v4l2_mpeg_compression *params); | ||
610 | void blackbird_set_dnr_params(struct cx8802_dev *dev, | ||
611 | struct blackbird_dnr* dnr_params); | ||
612 | 600 | ||
613 | /* | 601 | /* |
614 | * Local variables: | 602 | * Local variables: |