void GrabVBI (demux_t *p_demux, vlc_v4l2_vbi_t *vbi) { vbi_capture_buffer *sliced_bytes; struct timeval timeout= {0,0}; /* poll */ int canc = vlc_savecancel (); int r = vbi_capture_pull_sliced (vbi->cap, &sliced_bytes, &timeout); switch (r) { case -1: msg_Err (p_demux, "error reading VBI: %m"); case 0: /* nothing avail */ break; case 1: /* got data */ { int n_lines = sliced_bytes->size / sizeof(vbi_sliced); if (!n_lines) break; int sliced_size = 2; /* Number of bytes per sliced line */ int size = (sliced_size + 1) * n_lines; block_t *p_block = block_Alloc (size); if (unlikely(p_block == NULL)) break; uint8_t* data = p_block->p_buffer; vbi_sliced *sliced_array = sliced_bytes->data; for (int field = 0; field < n_lines; field++) { *data = field; data++; memcpy(data, sliced_array[field].data, sliced_size); data += sliced_size; } p_block->i_pts = mdate(); for (unsigned i = 0; i < VBI_NUM_CC_STREAMS; i++) { if (vbi->es[i] == NULL) continue; block_t *dup = block_Duplicate(p_block); if (likely(dup != NULL)) es_out_Send(p_demux->out, vbi->es[i], dup); } block_Release(p_block); } } vlc_restorecancel (canc); }
static GstFlowReturn gst_vbisrc_create(GstPushSrc *psrc, GstBuffer **buf) { Gstvbisrc *vbisrc = GST_VBISRC_CAST(psrc); GstFlowReturn ret; GstMapInfo info; fd_set rd; int res; struct timeval timeout; int vbi_fd=vbi_capture_fd(vbisrc->pVbiCapt); vbi_capture_buffer *pVbiBuf; vbi_sliced *pVbiData; GstBuffer *outbuf; uint lineCount; uint line; FD_ZERO(&rd); FD_SET(vbi_fd,&rd); select(vbi_fd +1 ,&rd , NULL, NULL, NULL); if (FD_ISSET(vbi_fd,&rd)) { timeout.tv_sec = 0; timeout.tv_usec = 1000; res = vbi_capture_pull_sliced(vbisrc->pVbiCapt,&pVbiBuf,&timeout); if (res>0 && pVbiBuf !=NULL) { lineCount = ((unsigned int)pVbiBuf->size)/sizeof(vbi_sliced); pVbiData = pVbiBuf->data; GST_LOG_OBJECT(vbisrc,"Having %d lines in buffer",lineCount); for (line=0; line<lineCount; line++ ) { if((pVbiData[line].id & (VBI_SLICED_TELETEXT_B))!=0) { GST_LOG_OBJECT(vbisrc,"SLICED_TELETEXT found in line %d",pVbiData[line].line); } } ret=GST_BASE_SRC_CLASS(parent_class) -> alloc (GST_BASE_SRC_CAST(vbisrc), -1,pVbiBuf->size,&outbuf); gst_buffer_map(outbuf,&info,GST_MAP_WRITE); memcpy(info.data,(guint8*)pVbiBuf->data,pVbiBuf->size); gst_buffer_unmap(outbuf,&info); *buf=GST_BUFFER_CAST(outbuf); GST_LOG_OBJECT (vbisrc,"Buffer pushed with size: %d", pVbiBuf->size); return ret; } } return GST_FLOW_ERROR; }