Debian Codegraph @

Xpjproject/pjmedia/src/pjmedia-videodev/colorbar_dev.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <pjmedia-videodev/videodev_imp.h>
19 #include <pjmedia/clock.h>
20 #include <pj/assert.h>
21 #include <pj/log.h>
22 #include <pj/os.h>
23 #include <pj/rand.h>
24
25
26 #if defined(PJMEDIA_HAS_VIDEO) && PJMEDIA_HAS_VIDEO != 0 && \
27 defined(PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC) && \
28 PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC != 0
29
30
31 #define THIS_FILE "colorbar_dev.c"
32 #define DEFAULT_CLOCK_RATE 90000
33 #define DEFAULT_WIDTH 352 //640
34 #define DEFAULT_HEIGHT 288 //480
35 #define DEFAULT_FPS 25
36
37
38 /* cbar_ device info */
39 struct cbar_dev_info
40 {
41 pjmedia_vid_dev_info info;
42 };
43
44 /* cbar_ factory */
45 struct cbar_factory
46 {
47 pjmedia_vid_dev_factory base;
48 pj_pool_t *pool;
49 pj_pool_factory *pf;
50
51 unsigned dev_count;
52 struct cbar_dev_info *dev_info;
53 };
54
55 struct cbar_fmt_info {
56 pjmedia_format_id fmt_id; /* Format ID */
57
58 /* Info for packed formats. */
59 unsigned c_offset[3]; /* Color component offset,
60 in bytes */
61 unsigned c_stride[3]; /* Color component stride,
62 or distance between two
63 consecutive same color
64 components, in bytes */
65 };
66
67 /* Colorbar video source supports */
68 static struct cbar_fmt_info cbar_fmts[] =
69 {
70 /* Packed formats */
71 { PJMEDIA_FORMAT_YUY2, {0, 1, 3}, {2, 4, 4} },
72 { PJMEDIA_FORMAT_UYVY, {1, 0, 2}, {2, 4, 4} },
73 { PJMEDIA_FORMAT_YVYU, {0, 3, 1}, {2, 4, 4} },
74 { PJMEDIA_FORMAT_RGBA, {0, 1, 2}, {4, 4, 4} },
75 { PJMEDIA_FORMAT_RGB24, {0, 1, 2}, {3, 3, 3} },
76 { PJMEDIA_FORMAT_BGRA, {2, 1, 0}, {4, 4, 4} },
77
78 /* Planar formats */
79 { PJMEDIA_FORMAT_YV12 },
80 { PJMEDIA_FORMAT_I420 },
81 { PJMEDIA_FORMAT_I422 },
82 { PJMEDIA_FORMAT_I420JPEG },
83 { PJMEDIA_FORMAT_I422JPEG },
84 };
85
86 /* Video stream. */
87 struct cbar_stream
88 {
89 pjmedia_vid_dev_stream base; /**< Base stream */
90 pjmedia_vid_dev_param param; /**< Settings */
91 pj_pool_t *pool; /**< Memory pool. */
92
93 pjmedia_vid_dev_cb vid_cb; /**< Stream callback. */
94 void *user_data; /**< Application data. */
95
96 const struct cbar_fmt_info *cbfi;
97 const pjmedia_video_format_info *vfi;
98 pjmedia_video_apply_fmt_param vafp;
99 pj_uint8_t *first_line[PJMEDIA_MAX_VIDEO_PLANES];
100 pj_timestamp ts;
101 unsigned ts_inc;
102
103 /* For active capturer only */
104 pjmedia_clock *clock;
105 pj_uint8_t *clock_buf;
106 };
107
108
109 /* Prototypes */
110 static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f);
111 static pj_status_t cbar_factory_destroy(pjmedia_vid_dev_factory *f);
112 static pj_status_t cbar_factory_refresh(pjmedia_vid_dev_factory *f);
113 static unsigned cbar_factory_get_dev_count(pjmedia_vid_dev_factory *f);
114 static pj_status_t cbar_factory_get_dev_info(pjmedia_vid_dev_factory *f,
115 unsigned index,
116 pjmedia_vid_dev_info *info);
117 static pj_status_t cbar_factory_default_param(pj_pool_t *pool,
118 pjmedia_vid_dev_factory *f,
119 unsigned index,
120 pjmedia_vid_dev_param *param);
121 static pj_status_t cbar_factory_create_stream(
122 pjmedia_vid_dev_factory *f,
123 pjmedia_vid_dev_param *param,
124 const pjmedia_vid_dev_cb *cb,
125 void *user_data,
126 pjmedia_vid_dev_stream **p_vid_strm);
127
128 static pj_status_t cbar_stream_get_param(pjmedia_vid_dev_stream *strm,
129 pjmedia_vid_dev_param *param);
130 static pj_status_t cbar_stream_get_cap(pjmedia_vid_dev_stream *strm,
131 pjmedia_vid_dev_cap cap,
132 void *value);
133 static pj_status_t cbar_stream_set_cap(pjmedia_vid_dev_stream *strm,
134 pjmedia_vid_dev_cap cap,
135 const void *value);
136 static pj_status_t cbar_stream_get_frame(pjmedia_vid_dev_stream *strm,
137 pjmedia_frame *frame);
138 static pj_status_t cbar_stream_start(pjmedia_vid_dev_stream *strm);
139 static pj_status_t cbar_stream_stop(pjmedia_vid_dev_stream *strm);
140 static pj_status_t cbar_stream_destroy(pjmedia_vid_dev_stream *strm);
141
142 /* Operations */
143 static pjmedia_vid_dev_factory_op factory_op =
144 {
145 &cbar_factory_init,
146 &cbar_factory_destroy,
147 &cbar_factory_get_dev_count,
148 &cbar_factory_get_dev_info,
149 &cbar_factory_default_param,
150 &cbar_factory_create_stream,
151 &cbar_factory_refresh
152 };
153
154 static pjmedia_vid_dev_stream_op stream_op =
155 {
156 &cbar_stream_get_param,
157 &cbar_stream_get_cap,
158 &cbar_stream_set_cap,
159 &cbar_stream_start,
160 &cbar_stream_get_frame,
161 NULL,
162 &cbar_stream_stop,
163 &cbar_stream_destroy
164 };
165
166
167 /****************************************************************************
168 * Factory operations
169 */
170 /*
171 * Init cbar_ video driver.
172 */
173 pjmedia_vid_dev_factory* pjmedia_cbar_factory(pj_pool_factory *pf)
174 {
175 struct cbar_factory *f;
176 pj_pool_t *pool;
177
178 pool = pj_pool_create(pf, "cbar video", 4000, 4000, NULL);
179 f = PJ_POOL_ZALLOC_T(pool, struct cbar_factory);
180 f->pf = pf;
181 f->pool = pool;
182 f->base.op = &factory_op;
183
184 return &f->base;
185 }
186
187
188 /* API: init factory */
189 static pj_status_t cbar_factory_init(pjmedia_vid_dev_factory *f)
190 {
191 struct cbar_factory *cf = (struct cbar_factory*)f;
192 struct cbar_dev_info *ddi;
193 unsigned i;
194
195 cf->dev_count = 2;
196
197 cf->dev_info = (struct cbar_dev_info*)
198 pj_pool_calloc(cf->pool, cf->dev_count,
199 sizeof(struct cbar_dev_info));
200
201 /* Passive capturer */
202 ddi = &cf->dev_info[0];
203 pj_bzero(ddi, sizeof(*ddi));
204 pj_ansi_strxcpy(ddi->info.name, "Colorbar generator",
205 sizeof(ddi->info.name));
206 pj_ansi_strxcpy(ddi->info.driver, "Colorbar",
207 sizeof(ddi->info.driver));
208 ddi->info.dir = PJMEDIA_DIR_CAPTURE;
209 ddi->info.has_callback = PJ_FALSE;
210
211 ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
212 ddi->info.fmt_cnt = PJ_ARRAY_SIZE(cbar_fmts);
213 for (i = 0; i < ddi->info.fmt_cnt; i++) {
214 pjmedia_format *fmt = &ddi->info.fmt[i];
215 pjmedia_format_init_video(fmt, cbar_fmts[i].fmt_id,
216 DEFAULT_WIDTH, DEFAULT_HEIGHT,
217 DEFAULT_FPS, 1);
218 }
219
220 /* Active capturer */
221 ddi = &cf->dev_info[1];
222 pj_bzero(ddi, sizeof(*ddi));
223 pj_ansi_strxcpy(ddi->info.name, "Colorbar-active",
224 sizeof(ddi->info.name));
225 pj_ansi_strxcpy(ddi->info.driver, "Colorbar",
226 sizeof(ddi->info.driver));
227 ddi->info.dir = PJMEDIA_DIR_CAPTURE;
228 ddi->info.has_callback = PJ_TRUE;
229
230 ddi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT;
231 ddi->info.fmt_cnt = PJ_ARRAY_SIZE(cbar_fmts);
232 for (i = 0; i < ddi->info.fmt_cnt; i++) {
233 pjmedia_format *fmt = &ddi->info.fmt[i];
234 pjmedia_format_init_video(fmt, cbar_fmts[i].fmt_id,
235 DEFAULT_WIDTH, DEFAULT_HEIGHT,
236 DEFAULT_FPS, 1);
237 }
238
239 PJ_LOG(4, (THIS_FILE, "Colorbar video src initialized with %d device(s):",
240 cf->dev_count));
241 for (i = 0; i < cf->dev_count; i++) {
242 PJ_LOG(4, (THIS_FILE, "%2d: %s", i, cf->dev_info[i].info.name));
243 }
244
245 return PJ_SUCCESS;
246 }
247
248 /* API: destroy factory */
249 static pj_status_t cbar_factory_destroy(pjmedia_vid_dev_factory *f)
250 {
251 struct cbar_factory *cf = (struct cbar_factory*)f;
252
253 pj_pool_safe_release(&cf->pool);
254
255 return PJ_SUCCESS;
256 }
257
258 /* API: refresh the list of devices */
259 static pj_status_t cbar_factory_refresh(pjmedia_vid_dev_factory *f)
260 {
261 PJ_UNUSED_ARG(f);
262 return PJ_SUCCESS;
263 }
264
265 /* API: get number of devices */
266 static unsigned cbar_factory_get_dev_count(pjmedia_vid_dev_factory *f)
267 {
268 struct cbar_factory *cf = (struct cbar_factory*)f;
269 return cf->dev_count;
270 }
271
272 /* API: get device info */
273 static pj_status_t cbar_factory_get_dev_info(pjmedia_vid_dev_factory *f,
274 unsigned index,
275 pjmedia_vid_dev_info *info)
276 {
277 struct cbar_factory *cf = (struct cbar_factory*)f;
278
279 PJ_ASSERT_RETURN(index < cf->dev_count, PJMEDIA_EVID_INVDEV);
280
281 pj_memcpy(info, &cf->dev_info[index].info, sizeof(*info));
282
283 return PJ_SUCCESS;
284 }
285
286 /* API: create default device parameter */
287 static pj_status_t cbar_factory_default_param(pj_pool_t *pool,
288 pjmedia_vid_dev_factory *f,
289 unsigned index,
290 pjmedia_vid_dev_param *param)
291 {
292 struct cbar_factory *cf = (struct cbar_factory*)f;
293 struct cbar_dev_info *di = &cf->dev_info[index];
294
295 PJ_ASSERT_RETURN(index < cf->dev_count, PJMEDIA_EVID_INVDEV);
296
297 PJ_UNUSED_ARG(pool);
298
299 pj_bzero(param, sizeof(*param));
300 param->dir = PJMEDIA_DIR_CAPTURE;
301 param->cap_id = index;
302 param->rend_id = PJMEDIA_VID_INVALID_DEV;
303 param->flags = PJMEDIA_VID_DEV_CAP_FORMAT;
304 param->clock_rate = DEFAULT_CLOCK_RATE;
305 pj_memcpy(&param->fmt, &di->info.fmt[0], sizeof(param->fmt));
306
307 return PJ_SUCCESS;
308 }
309
310 static const struct cbar_fmt_info* get_cbar_fmt_info(pjmedia_format_id id)
311 {
312 unsigned i;
313
314 for (i = 0; i < PJ_ARRAY_SIZE(cbar_fmts); i++) {
315 if (cbar_fmts[i].fmt_id == id)
316 return &cbar_fmts[i];
317 }
318
319 return NULL;
320 }
321
322 static void fill_first_line(pj_uint8_t *first_lines[],
323 const struct cbar_fmt_info *cbfi,
324 const pjmedia_video_format_info *vfi,
325 const pjmedia_video_apply_fmt_param *vafp)
326 {
327 typedef pj_uint8_t color_comp_t[3];
328 color_comp_t rgb_colors[] =
329 {
330 {255,255,255}, {255,255,0}, {0,255,255}, {0,255,0},
331 {255,0,255}, {255,0,0}, {0,0,255}, {0,0,0}
332 };
333 color_comp_t yuv_colors[] =
334 {
335 //{235,128,128}, {162,44,142}, {131,156,44}, {112,72,58},
336 //{84,184,198}, {65,100,212}, {35,212,114}, {16,128,128}
337 {235,128,128}, {210,16,146}, {170,166,16}, {145,54,34},
338 {106,202,222}, {81,90,240}, {41,240,110}, {16,128,128}
339 };
340
341 unsigned i, j, k;
342
343 if (vfi->plane_cnt == 1) {
344 /* Packed */
345
346 for (i = 0; i < 8; ++i) {
347 /* iterate bars */
348 for (j = 0; j < 3; ++j) {
349 /* iterate color components */
350 pj_uint8_t *p = NULL, c;
351 unsigned bar_width, inc_p;
352
353 if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
354 c = rgb_colors[i][j];
355 else
356 c = yuv_colors[i][j];
357
358 bar_width = vafp->size.w/8;
359 bar_width /= (cbfi->c_stride[j] * 8 / vfi->bpp);
360 inc_p = cbfi->c_stride[j];
361 p = first_lines[0] + bar_width*i*inc_p + cbfi->c_offset[j];
362
363 /* draw this color */
364 for (k = 0; k < bar_width; ++k) {
365 *p = c;
366 p += inc_p;
367 }
368 }
369 }
370
371 } else if (vfi->plane_cnt == 3) {
372
373 for (i = 0; i < 8; ++i) {
374 /* iterate bars */
375 for (j = 0; j < 3; ++j) {
376 /* iterate planes/color components */
377 pj_uint8_t *p = NULL, c;
378 unsigned bar_width;
379
380 if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
381 c = rgb_colors[i][j];
382 else {
383 if (vfi->id == PJMEDIA_FORMAT_YV12 && j > 0)
384 c = yuv_colors[i][3-j];
385 else
386 c = yuv_colors[i][j];
387 }
388
389 bar_width = vafp->strides[j]/8;
390 p = first_lines[j] + bar_width*i;
391
392 /* draw this plane/color */
393 for (k = 0; k < bar_width; ++k)
394 *p++ = c;
395 }
396 }
397 }
398 }
399
400
401 static void clock_cb(const pj_timestamp *ts, void *user_data)
402 {
403 struct cbar_stream *stream = (struct cbar_stream*)user_data;
404 pjmedia_frame f;
405 pj_status_t status;
406
407 PJ_UNUSED_ARG(ts);
408
409 pj_bzero(&f, sizeof(f));
410 f.buf = stream->clock_buf;
411 f.size = stream->vafp.framebytes;
412 status = cbar_stream_get_frame(&stream->base, &f);
413 if (status == PJ_SUCCESS) {
414 (*stream->vid_cb.capture_cb)(&stream->base, stream->user_data, &f);
415 }
416 }
417
418
419 /* API: create stream */
420 static pj_status_t cbar_factory_create_stream(
421 pjmedia_vid_dev_factory *f,
422 pjmedia_vid_dev_param *param,
423 const pjmedia_vid_dev_cb *cb,
424 void *user_data,
425 pjmedia_vid_dev_stream **p_vid_strm)
426 {
427 struct cbar_factory *cf = (struct cbar_factory*)f;
428 pj_pool_t *pool;
429 struct cbar_stream *strm;
430 const pjmedia_video_format_detail *vfd;
431 const pjmedia_video_format_info *vfi;
432 pjmedia_video_apply_fmt_param vafp;
433 const struct cbar_fmt_info *cbfi;
434 unsigned i;
435
436 PJ_ASSERT_RETURN(f && param && p_vid_strm, PJ_EINVAL);
437 PJ_ASSERT_RETURN(param->fmt.type == PJMEDIA_TYPE_VIDEO &&
438 param->fmt.detail_type == PJMEDIA_FORMAT_DETAIL_VIDEO &&
439 param->dir == PJMEDIA_DIR_CAPTURE,
440 PJ_EINVAL);
441
442 pj_bzero(&vafp, sizeof(vafp));
443
444 vfd = pjmedia_format_get_video_format_detail(&param->fmt, PJ_TRUE);
445 vfi = pjmedia_get_video_format_info(NULL, param->fmt.id);
446 cbfi = get_cbar_fmt_info(param->fmt.id);
447 if (!vfi || !cbfi)
448 return PJMEDIA_EVID_BADFORMAT;
449
450 vafp.size = param->fmt.det.vid.size;
451 if (vfi->apply_fmt(vfi, &vafp) != PJ_SUCCESS)
452 return PJMEDIA_EVID_BADFORMAT;
453
454 /* Create and Initialize stream descriptor */
455 pool = pj_pool_create(cf->pf, "cbar-dev", 512, 512, NULL);
456 PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
457
458 strm = PJ_POOL_ZALLOC_T(pool, struct cbar_stream);
459 pj_memcpy(&strm->param, param, sizeof(*param));
460 strm->pool = pool;
461 pj_memcpy(&strm->vid_cb, cb, sizeof(*cb));
462 strm->user_data = user_data;
463 strm->vfi = vfi;
464 strm->cbfi = cbfi;
465 pj_memcpy(&strm->vafp, &vafp, sizeof(vafp));
466 strm->ts_inc = PJMEDIA_SPF2(param->clock_rate, &vfd->fps, 1);
467
468 for (i = 0; i < vfi->plane_cnt; ++i) {
469 strm->first_line[i] = pj_pool_alloc(pool, vafp.strides[i]);
470 pj_memset(strm->first_line[i], 255, vafp.strides[i]);
471 }
472
473 fill_first_line(strm->first_line, strm->cbfi, vfi, &strm->vafp);
474
475 /* Apply the remaining settings */
476 /* if (param->flags & PJMEDIA_VID_DEV_CAP_INPUT_SCALE) {
477 cbar_stream_set_cap(&strm->base,
478 PJMEDIA_VID_DEV_CAP_INPUT_SCALE,
479 &param->fmt);
480 }
481 */
482
483 /* Active role? */
484 if (param->cap_id == 1 && cb && cb->capture_cb) {
485 pjmedia_clock_param clock_param;
486 pj_status_t status;
487
488 /* Allocate buffer */
489 strm->clock_buf = pj_pool_alloc(pool, strm->vafp.framebytes);
490
491 /* Create clock */
492 pj_bzero(&clock_param, sizeof(clock_param));
493 clock_param.usec_interval = PJMEDIA_PTIME(&vfd->fps);
494 clock_param.clock_rate = param->clock_rate;
495 status = pjmedia_clock_create2(pool, &clock_param,
496 PJMEDIA_CLOCK_NO_HIGHEST_PRIO,
497 &clock_cb,
498 strm, &strm->clock);
499 if (status != PJ_SUCCESS) {
500 pj_pool_release(pool);
501 return status;
502 }
503 }
504
505 /* Done */
506 strm->base.op = &stream_op;
507 *p_vid_strm = &strm->base;
508
509 return PJ_SUCCESS;
510 }
511
512 /* API: Get stream info. */
513 static pj_status_t cbar_stream_get_param(pjmedia_vid_dev_stream *s,
514 pjmedia_vid_dev_param *pi)
515 {
516 struct cbar_stream *strm = (struct cbar_stream*)s;
517
518 PJ_ASSERT_RETURN(strm && pi, PJ_EINVAL);
519
520 pj_memcpy(pi, &strm->param, sizeof(*pi));
521
522 /* if (cbar_stream_get_cap(s, PJMEDIA_VID_DEV_CAP_INPUT_SCALE,
523 &pi->fmt.info_size) == PJ_SUCCESS)
524 {
525 pi->flags |= PJMEDIA_VID_DEV_CAP_INPUT_SCALE;
526 }
527 */
528 return PJ_SUCCESS;
529 }
530
531 /* API: get capability */
532 static pj_status_t cbar_stream_get_cap(pjmedia_vid_dev_stream *s,
533 pjmedia_vid_dev_cap cap,
534 void *pval)
535 {
536 struct cbar_stream *strm = (struct cbar_stream*)s;
537
538 PJ_UNUSED_ARG(strm);
539
540 PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
541
542 if (cap==PJMEDIA_VID_DEV_CAP_INPUT_SCALE)
543 {
544 return PJMEDIA_EVID_INVCAP;
545 // return PJ_SUCCESS;
546 } else {
547 return PJMEDIA_EVID_INVCAP;
548 }
549 }
550
551 /* API: set capability */
552 static pj_status_t cbar_stream_set_cap(pjmedia_vid_dev_stream *s,
553 pjmedia_vid_dev_cap cap,
554 const void *pval)
555 {
556 struct cbar_stream *strm = (struct cbar_stream*)s;
557
558 PJ_UNUSED_ARG(strm);
559
560 PJ_ASSERT_RETURN(s && pval, PJ_EINVAL);
561
562 if (cap==PJMEDIA_VID_DEV_CAP_INPUT_SCALE)
563 {
564 return PJ_SUCCESS;
565 }
566
567 return PJMEDIA_EVID_INVCAP;
568 }
569
570 static pj_status_t spectrum_run(struct cbar_stream *d, pj_uint8_t *p,
571 pj_size_t size)
572 {
573 unsigned i;
574 pj_uint8_t *ptr = p;
575 pj_time_val tv;
576
577 PJ_UNUSED_ARG(size);
578
579 /* Subsequent lines */
580 for (i=0; i<d->vfi->plane_cnt; ++i) {
581 pj_uint8_t *plane_end;
582
583 plane_end = ptr + d->vafp.plane_bytes[i];
584 while (ptr < plane_end) {
585 pj_memcpy(ptr, d->first_line[i], d->vafp.strides[i]);
586 ptr += d->vafp.strides[i];
587 }
588 }
589
590 /* blinking dot */
591 pj_gettimeofday(&tv);
592 if (tv.msec < 660) {
593 enum { DOT_SIZE = 8 };
594 pj_uint8_t dot_clr_rgb[3] = {255, 255, 255};
595 pj_uint8_t dot_clr_yuv[3] = {235, 128, 128};
596
597 if (d->vfi->plane_cnt == 1) {
598 for (i = 0; i < 3; ++i) {
599 unsigned j, k, inc_ptr;
600 pj_size_t dot_size = DOT_SIZE;
601
602 dot_size /= (d->cbfi->c_stride[i] * 8 / d->vfi->bpp);
603 inc_ptr = d->cbfi->c_stride[i];
604 for (j = 0; j < dot_size; ++j) {
605 ptr = p + d->vafp.strides[0]*(dot_size+j+1) -
606 2*dot_size*inc_ptr + d->cbfi->c_offset[i];
607 for (k = 0; k < dot_size; ++k) {
608 if (d->vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
609 *ptr = dot_clr_rgb[i];
610 else
611 *ptr = dot_clr_yuv[i];
612 ptr += inc_ptr;
613 }
614 }
615 }
616 } else {
617 pj_size_t offset_p = 0;
618
619 for (i = 0; i < 3; ++i) {
620 pj_uint8_t c;
621 unsigned j;
622 pj_size_t dot_size = DOT_SIZE;
623
624 if (d->vfi->color_model == PJMEDIA_COLOR_MODEL_RGB)
625 c = dot_clr_rgb[i];
626 else
627 c = dot_clr_yuv[i];
628
629 dot_size /= (d->vafp.size.w / d->vafp.strides[i]);
630 ptr = p + offset_p + d->vafp.strides[i]*(dot_size+1) -
631 2*dot_size;
632 for (j = 0; j < dot_size; ++j) {
633 pj_memset(ptr, c, dot_size);
634 ptr += d->vafp.strides[i];
635 }
636 offset_p += d->vafp.plane_bytes[i];
637 }
638 }
639 }
640
641 return PJ_SUCCESS;
642 }
643
644 /* API: Get frame from stream */
645 static pj_status_t cbar_stream_get_frame(pjmedia_vid_dev_stream *strm,
646 pjmedia_frame *frame)
647 {
648 struct cbar_stream *stream = (struct cbar_stream*)strm;
649
650 frame->type = PJMEDIA_FRAME_TYPE_VIDEO;
651 frame->bit_info = 0;
652 frame->timestamp = stream->ts;
653 stream->ts.u64 += stream->ts_inc;
654 return spectrum_run(stream, frame->buf, frame->size);
655 }
656
657 /* API: Start stream. */
658 static pj_status_t cbar_stream_start(pjmedia_vid_dev_stream *strm)
659 {
660 struct cbar_stream *stream = (struct cbar_stream*)strm;
661
662 PJ_LOG(4, (THIS_FILE, "Starting cbar video stream"));
663
664 if (stream->clock)
665 return pjmedia_clock_start(stream->clock);
666
667 return PJ_SUCCESS;
668 }
669
670 /* API: Stop stream. */
671 static pj_status_t cbar_stream_stop(pjmedia_vid_dev_stream *strm)
672 {
673 struct cbar_stream *stream = (struct cbar_stream*)strm;
674
675 PJ_LOG(4, (THIS_FILE, "Stopping cbar video stream"));
676
677 if (stream->clock)
678 return pjmedia_clock_stop(stream->clock);
679
680 return PJ_SUCCESS;
681 }
682
683
684 /* API: Destroy stream. */
685 static pj_status_t cbar_stream_destroy(pjmedia_vid_dev_stream *strm)
686 {
687 struct cbar_stream *stream = (struct cbar_stream*)strm;
688
689 PJ_ASSERT_RETURN(stream != NULL, PJ_EINVAL);
690
691 cbar_stream_stop(strm);
692
693 if (stream->clock)
694 pjmedia_clock_destroy(stream->clock);
695 stream->clock = NULL;
696
697 pj_pool_release(stream->pool);
698
699 return PJ_SUCCESS;
700 }
701
702 #endif /* PJMEDIA_VIDEO_DEV_HAS_CBAR_SRC */