static nserror nsvideo_create(const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c) { nsvideo_content *video; nserror error; GstBus *bus; video = calloc(1, sizeof(nsvideo_content)); if (video == NULL) return NSERROR_NOMEM; error = content__init(&video->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { free(video); return error; } error = llcache_handle_force_stream(llcache); if (error != NSERROR_OK) { free(video); return error; } video->playbin = gst_element_factory_make("playbin2", NULL); if (video->playbin == NULL) { free(video); return NSERROR_NOMEM; } bus = gst_pipeline_get_bus(GST_PIPELINE(video->playbin)); gst_bus_add_watch(bus, (GstBusFunc) nsvideo_bus_call, video); gst_object_unref(bus); g_object_set(video->playbin, "uri", "appsrc://", NULL); g_signal_connect(video->playbin, "deep-notify::source", G_CALLBACK(nsvideo_source_event), video); /** \todo Create appsink & register with playbin */ gst_element_set_state(video->playbin, GST_STATE_PLAYING); *c = (struct content *) video; return NSERROR_OK; }
/** * Migrate a retrieval context into its final destination content * * \param ctx Context to migrate * \param effective_type The effective MIME type of the content, or NULL * \return NSERROR_OK on success, * NSERROR_NEED_DATA on success where data is needed, * appropriate error otherwise */ static nserror hlcache_migrate_ctx(hlcache_retrieval_ctx *ctx, lwc_string *effective_type) { content_type type = CONTENT_NONE; nserror error = NSERROR_OK; ctx->migrate_target = true; if (effective_type != NULL && hlcache_type_is_acceptable(effective_type, ctx->accepted_types, &type)) { error = hlcache_find_content(ctx, effective_type); if (error != NSERROR_OK && error != NSERROR_NEED_DATA) { if (ctx->handle->cb != NULL) { hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; hlevent.data.error = messages_get("MiscError"); ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); } llcache_handle_abort(ctx->llcache); llcache_handle_release(ctx->llcache); } } else if (type == CONTENT_NONE && (ctx->flags & HLCACHE_RETRIEVE_MAY_DOWNLOAD)) { /* Unknown type, and we can download, so convert */ llcache_handle_force_stream(ctx->llcache); if (ctx->handle->cb != NULL) { hlcache_event hlevent; hlevent.type = CONTENT_MSG_DOWNLOAD; hlevent.data.download = ctx->llcache; ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); } /* Ensure caller knows we need data */ error = NSERROR_NEED_DATA; } else { /* Unacceptable type: report error */ if (ctx->handle->cb != NULL) { hlcache_event hlevent; hlevent.type = CONTENT_MSG_ERROR; hlevent.data.error = messages_get("UnacceptableType"); ctx->handle->cb(ctx->handle, &hlevent, ctx->handle->pw); } llcache_handle_abort(ctx->llcache); llcache_handle_release(ctx->llcache); } ctx->migrate_target = false; /* No longer require retrieval context */ RING_REMOVE(hlcache->retrieval_ctx_ring, ctx); free((char *) ctx->child.charset); free(ctx); return error; }