static gboolean gst_v4l2_buffer_pool_start (GstBufferPool * bpool) { GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); GstV4l2Object *obj = pool->obj; pool->obj = obj; pool->buffers = g_new0 (GstBuffer *, pool->num_buffers); pool->num_allocated = 0; /* now, allocate the buffers: */ if (!GST_BUFFER_POOL_CLASS (parent_class)->start (bpool)) goto start_failed; /* we can start capturing now, we wait for the playback case until we queued * the first buffer */ if (obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) if (!start_streaming (pool)) goto start_failed; gst_poll_set_flushing (obj->poll, FALSE); return TRUE; /* ERRORS */ start_failed: { GST_ERROR_OBJECT (pool, "failed to start streaming"); return FALSE; } }
static int encode_update(struct videnc_state **vesp, const struct vidcodec *vc, struct videnc_param *prm, const char *fmtp, videnc_packet_h *pkth, void *arg) { struct videnc_state *st; int err = 0; (void)fmtp; if (!vesp || !vc || !prm || !pkth) return EINVAL; if (*vesp) return 0; st = mem_zalloc(sizeof(*st), enc_destructor); if (!st) return ENOMEM; st->encprm = *prm; st->pkth = pkth; st->arg = arg; st->fd = open(v4l2.device, O_RDWR); if (st->fd == -1) { err = errno; warning("Opening video device (%m)\n", err); goto out; } err = print_caps(st->fd); if (err) goto out; err = init_mmap(st, st->fd); if (err) goto out; err = query_buffer(st->fd); if (err) goto out; err = start_streaming(st->fd); if (err) goto out; err = fd_listen(st->fd, FD_READ, read_handler, st); if (err) goto out; info("v4l2_codec: video encoder %s: %d fps, %d bit/s, pktsize=%u\n", vc->name, prm->fps, prm->bitrate, prm->pktsize); out: if (err) mem_deref(st); else *vesp = st; return err; }
static int initialize_capture(v4l2_std_id * cur_std) { int ret; printf("initializing capture device\n"); init_capture_device(); printf("setting data format\n"); ret = set_data_format(cur_std); if (ret) { printf("Error in setting capture format\n"); return ret; } printf("initializing capture buffers\n"); ret = init_capture_buffers(); if (ret) { printf("Failed to initialize capture buffers\n"); return ret; } printf("initializing display device\n"); ret = start_streaming(); if (ret) { printf("Failed to start capture streaming\n"); return ret; } return 0; }
int main(int argc, char *argv[]) { rtsplink_t vidout; int ret = start_streaming(&vidout, HOST, PORT); if (ret == -1) { printf("stopping due to error\n"); return 1; } while (!stopsig) ; stop_streaming(&vidout); return 0; }
JNIEXPORT void JNICALL Java_com_desktopStreamer_VideoStreamer_stream(JNIEnv *env, jobject obj) { env->GetJavaVM(&g_vm); std::cout << "Starting native stream" << std::endl; /* get stream callback method*/ g_obj = env->NewGlobalRef(obj); jclass g_clazz = env->GetObjectClass(g_obj); if(g_clazz == NULL) { std::cout << "Failed to find class" << std::endl; } g_mid = env->GetMethodID(g_clazz, "streamByte", "([B)V"); if(g_mid == NULL) { std::cout << "Unable to get method ref" << std::endl; } /* start stream */ start_streaming(); }
static int start_feed(struct dvb_demux_feed *feed) { struct dvb_demux *demux = feed->demux; struct em28xx_dvb *dvb = demux->priv; int rc, ret; if (!demux->dmx.frontend) return -EINVAL; mutex_lock(&dvb->lock); dvb->nfeeds++; rc = dvb->nfeeds; if (dvb->nfeeds == 1) { ret = start_streaming(dvb); if (ret < 0) rc = ret; } mutex_unlock(&dvb->lock); return rc; }
/** * gst_v4l2_buffer_pool_process: * @bpool: a #GstBufferPool * @buf: a #GstBuffer * * Process @buf in @bpool. For capture devices, this functions fills @buf with * data from the device. For output devices, this functions send the contents of * @buf to the device for playback. * * Returns: %GST_FLOW_OK on success. */ GstFlowReturn gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer * buf) { GstFlowReturn ret = GST_FLOW_OK; GstBufferPool *bpool = GST_BUFFER_POOL_CAST (pool); GstV4l2Object *obj = pool->obj; GST_DEBUG_OBJECT (pool, "process buffer %p", buf); switch (obj->type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: /* capture */ switch (obj->mode) { case GST_V4L2_IO_RW: /* capture into the buffer */ ret = gst_v4l2_do_read (pool, buf); break; case GST_V4L2_IO_MMAP: { GstBuffer *tmp; if (buf->pool == bpool) /* nothing, data was inside the buffer when we did _acquire() */ goto done; /* buffer not from our pool, grab a frame and copy it into the target */ if ((ret = gst_v4l2_buffer_pool_dqbuf (pool, &tmp)) != GST_FLOW_OK) goto done; if (!gst_v4l2_object_copy (obj, buf, tmp)) goto copy_failed; /* an queue the buffer again after the copy */ if ((ret = gst_v4l2_buffer_pool_qbuf (pool, tmp)) != GST_FLOW_OK) goto done; break; } case GST_V4L2_IO_USERPTR: default: g_assert_not_reached (); break; } break; case V4L2_BUF_TYPE_VIDEO_OUTPUT: /* playback */ switch (obj->mode) { case GST_V4L2_IO_RW: /* FIXME, do write() */ GST_WARNING_OBJECT (pool, "implement write()"); break; case GST_V4L2_IO_MMAP: { GstBuffer *to_queue; if (buf->pool == bpool) { /* nothing, we can queue directly */ to_queue = buf; GST_LOG_OBJECT (pool, "processing buffer from our pool"); } else { GST_LOG_OBJECT (pool, "alloc buffer from our pool"); if (!gst_buffer_pool_is_active (bpool)) { GstStructure *config; /* this pool was not activated, configure and activate */ GST_DEBUG_OBJECT (pool, "activating pool"); config = gst_buffer_pool_get_config (bpool); gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META); gst_buffer_pool_set_config (bpool, config); if (!gst_buffer_pool_set_active (bpool, TRUE)) goto activate_failed; } /* this can block if all buffers are outstanding which would be * strange because we would expect the upstream element to have * allocated them and returned to us.. */ ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (bpool, &to_queue, NULL); if (ret != GST_FLOW_OK) goto acquire_failed; /* copy into it and queue */ if (!gst_v4l2_object_copy (obj, to_queue, buf)) goto copy_failed; } if ((ret = gst_v4l2_buffer_pool_qbuf (pool, to_queue)) != GST_FLOW_OK) goto done; /* if we are not streaming yet (this is the first buffer, start * streaming now */ if (!pool->streaming) if (!start_streaming (pool)) goto start_failed; if (pool->num_queued == pool->num_allocated) { /* all buffers are queued, try to dequeue one and release it back * into the pool so that _acquire can get to it again. */ ret = gst_v4l2_buffer_pool_dqbuf (pool, &to_queue); if (ret != GST_FLOW_OK) goto done; /* release the rendered buffer back into the pool. This wakes up any * thread waiting for a buffer in _acquire() */ gst_v4l2_buffer_pool_release_buffer (bpool, to_queue); } break; } case GST_V4L2_IO_USERPTR: default: g_assert_not_reached (); break; } break; default: g_assert_not_reached (); break; } done: return ret; /* ERRORS */ activate_failed: { GST_ERROR_OBJECT (obj->element, "failed to activate pool"); return GST_FLOW_ERROR; } acquire_failed: { GST_WARNING_OBJECT (obj->element, "failed to acquire a buffer: %s", gst_flow_get_name (ret)); return ret; } copy_failed: { GST_ERROR_OBJECT (obj->element, "failed to copy data"); return GST_FLOW_ERROR; } start_failed: { GST_ERROR_OBJECT (obj->element, "failed to start streaming"); return GST_FLOW_ERROR; } }
int main(int argc,char *argv[]) { start_streaming(); }
/** * \brief Joins multicast group and receives UDP datagram on the UDP socket 224.2.127.254:9875, payload contains SAP/SDP message (announcement or deletion) * \return gboolean TRUE on succed, FALSE on failure */ gboolean receive_announcement(){ int status; int udp_payload_length = SAP_MAX_size; char udp_payload[SAP_MAX_size]; status = read( sap_socket.udp_socket_fd_rec, udp_payload, udp_payload_length ); if (status == -1) { g_debug("Failed to receive: %s", strerror(errno)); return TRUE; } else if ( status == sizeof(udp_payload )) { g_warning("datagram too large for buffer: truncated"); return TRUE; } else { /* compare the payloed read on the socket with the payload read before * if there different, save the new payload into the sap_dat of the channel */ /* check if it is the one we should be listening to */ unsigned char *sdp_msg = (unsigned char*) SAP_depay(udp_payload); /* struct to save the multicast IP of the receive stream */ in_addr_t multicast_addr; char channel_desc[DisplayString64]; /* the maximum size of the channelDesc is 64 bytes */ GstCaps* caps = get_SDP(sdp_msg, status - SAP_header_size, &multicast_addr, channel_desc); /* if caps are null, a problem occured or this is not a SAP/SDP announcement from the right channel */ if(caps == NULL ) return TRUE; /* we cannot return FALSE, cause we need to keep on listenning for our SAP/SDP annoucement */ struct channelTable_entry* iterator = channelTable_SU_head; while (iterator != NULL ) { if (iterator->channelReceiveIpAddress == multicast_addr) { /* Now we are sure that this is our SAP/SDP annoucement */ /* check if the SAP message is a deletion message */ if( udp_payload[0] == SAP_header_deletion ){ delete_steaming_data(iterator); /* delet streaming has it is stopped */ } else { stream_data *data = iterator->stream_datas; /* * If pipeline is not created yet, create it and start to display the stream */ if ( data == NULL ) { if ( !init_stream_SU ( caps, iterator ) ) start_streaming ( iterator->stream_datas, iterator->channelVideoFormatIndex ); /* init the video channelUserDesc field */ iterator->channelUserDesc = strdup( (const char*) channel_desc); iterator->channelUserDesc_len = strlen(channel_desc); } /* * otherwise, replace udpsrc element's caps with the caps extracted from SDP file */ else { GstCaps *current_caps; g_object_get ( G_OBJECT ( data->udp_elem ) , "caps" , ¤t_caps , NULL ) ; if ( ! gst_caps_is_equal ( caps, current_caps ) ){ gst_element_set_state (data->pipeline, GST_STATE_NULL ) ; set_udpsrc_param( data->udp_elem , iterator , caps ) ; update_channelTable_entry_roi_from_caps ( iterator , caps ) ; gst_element_set_state (data->pipeline, GST_STATE_PLAYING); } } } } iterator = iterator->next_SU; } return TRUE; } }