bool gst_vlc_set_vout_fmt( GstVideoInfo *p_info, GstVideoAlignment *p_align, GstCaps *p_caps, decoder_t *p_dec ) { es_format_t *p_outfmt = &p_dec->fmt_out; video_format_t *p_voutfmt = &p_dec->fmt_out.video; GstStructure *p_str = gst_caps_get_structure( p_caps, 0 ); vlc_fourcc_t i_chroma; int i_padded_width, i_padded_height; i_chroma = p_outfmt->i_codec = vlc_fourcc_GetCodecFromString( VIDEO_ES, gst_structure_get_string( p_str, "format" ) ); if( !i_chroma ) { msg_Err( p_dec, "video chroma type not supported" ); return false; } i_padded_width = GST_VIDEO_INFO_WIDTH( p_info ) + p_align->padding_left + p_align->padding_right; i_padded_height = GST_VIDEO_INFO_HEIGHT( p_info ) + p_align->padding_top + p_align->padding_bottom; video_format_Setup( p_voutfmt, i_chroma, i_padded_width, i_padded_height, GST_VIDEO_INFO_WIDTH( p_info ), GST_VIDEO_INFO_HEIGHT( p_info ), GST_VIDEO_INFO_PAR_N( p_info ), GST_VIDEO_INFO_PAR_D( p_info )); p_voutfmt->i_x_offset = p_align->padding_left; p_voutfmt->i_y_offset = p_align->padding_top; p_voutfmt->i_frame_rate = GST_VIDEO_INFO_FPS_N( p_info ); p_voutfmt->i_frame_rate_base = GST_VIDEO_INFO_FPS_D( p_info ); return true; }
/***************************************************************************** * OpenVideo: activates dummy vout display method *****************************************************************************/ static int Open(vlc_object_t *object, void (*display)(vout_display_t *, picture_t *, subpicture_t *)) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) return VLC_EGENERIC; sys->pool = NULL; /* p_vd->info is not modified */ char *chroma = var_InheritString(vd, "dummy-chroma"); if (chroma) { vlc_fourcc_t fcc = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma); if (fcc != 0) { msg_Dbg(vd, "forcing chroma 0x%.8x (%4.4s)", fcc, (char*)&fcc); vd->fmt.i_chroma = fcc; } free(chroma); } vd->pool = Pool; vd->prepare = NULL; vd->display = display; vd->control = Control; vd->manage = NULL; vout_display_DeleteWindow(vd, NULL); return VLC_SUCCESS; }
static vlc_fourcc_t var_InheritFourCC (vlc_object_t *obj, const char *varname) { char *str = var_InheritString (obj, varname); if (str == NULL) return 0; vlc_fourcc_t fourcc = vlc_fourcc_GetCodecFromString (VIDEO_ES, str); if (fourcc == 0) msg_Err (obj, "invalid codec %s", str); free (str); return fourcc; }
/** * This function allocates and initializes a FB vout method. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* Allocate instance and initialize some members */ vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; /* Does the framebuffer uses hw acceleration? */ sys->is_hw_accel = var_InheritBool(vd, "fb-hw-accel"); /* Set tty and fb devices */ sys->tty = 0; /* 0 == /dev/tty0 == current console */ sys->is_tty = var_InheritBool(vd, "fb-tty"); #if !defined(_WIN32) && defined(HAVE_ISATTY) /* Check that stdin is a TTY */ if (sys->is_tty && !isatty(0)) { msg_Warn(vd, "standard input is not a TTY"); free(sys); return VLC_EGENERIC; } msg_Warn(vd, "disabling TTY handling, use with caution because " "there is no way to return to the TTY"); #endif const int mode = var_InheritInteger(vd, "fb-mode"); bool force_resolution = true; switch (mode) { case 0: /* QCIF */ sys->width = 176; sys->height = 144; break; case 1: /* CIF */ sys->width = 352; sys->height = 288; break; case 2: /* NTSC */ sys->width = 640; sys->height = 480; break; case 3: /* PAL */ sys->width = 704; sys->height = 576; break; case 4: default: force_resolution = false; break; } char *chroma = var_InheritString(vd, "fb-chroma"); if (chroma) { sys->chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma); if (sys->chroma) msg_Dbg(vd, "forcing chroma '%s'", chroma); else msg_Warn(vd, "chroma %s invalid, using default", chroma); free(chroma); } else sys->chroma = 0; /* tty handling */ if (sys->is_tty && TtyInit(vd)) { free(sys); return VLC_EGENERIC; } /* */ sys->video_ptr = MAP_FAILED; sys->picture = NULL; sys->pool = NULL; if (OpenDisplay(vd, force_resolution)) { Close(VLC_OBJECT(vd)); return VLC_EGENERIC; } vout_display_DeleteWindow(vd, NULL); /* */ video_format_t fmt = vd->fmt; if (sys->chroma) { fmt.i_chroma = sys->chroma; } else { /* Assume RGB */ msg_Dbg(vd, "%d bppd", sys->var_info.bits_per_pixel); switch (sys->var_info.bits_per_pixel) { case 8: /* FIXME: set the palette */ fmt.i_chroma = VLC_CODEC_RGB8; break; case 15: fmt.i_chroma = VLC_CODEC_RGB15; break; case 16: fmt.i_chroma = VLC_CODEC_RGB16; break; case 24: fmt.i_chroma = VLC_CODEC_RGB24; break; case 32: fmt.i_chroma = VLC_CODEC_RGB32; break; default: msg_Err(vd, "unknown screendepth %i", sys->var_info.bits_per_pixel); Close(VLC_OBJECT(vd)); return VLC_EGENERIC; } if (sys->var_info.bits_per_pixel != 8) { fmt.i_rmask = ((1 << sys->var_info.red.length) - 1) << sys->var_info.red.offset; fmt.i_gmask = ((1 << sys->var_info.green.length) - 1) << sys->var_info.green.offset; fmt.i_bmask = ((1 << sys->var_info.blue.length) - 1) << sys->var_info.blue.offset; } } fmt.i_visible_width = sys->width; fmt.i_visible_height = sys->height; /* */ vout_display_info_t info = vd->info; info.has_hide_mouse = true; /* */ vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = NULL; /* */ vout_display_SendEventFullscreen(vd, true); vout_display_SendEventDisplaySize(vd, fmt.i_visible_width, fmt.i_visible_height, true); return VLC_SUCCESS; }
/***************************************************************************** * OpenDecoder: probe the decoder and return score *****************************************************************************/ static int OpenDecoder( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; decoder_sys_t *p_sys; char *psz_tmp; int pitch; if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e')) { return VLC_EGENERIC; } /* Allocate the memory needed to store the decoder's structure */ if( ( p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t)) ) == NULL ) return VLC_ENOMEM; // get parameters char* chromaStr = var_CreateGetString( p_dec, "invmem-chroma" ); p_sys->i_width = var_CreateGetInteger( p_this, "invmem-width" ); p_sys->i_height = var_CreateGetInteger( p_this, "invmem-height" ); if( p_sys->i_width == 0 || p_sys->i_height == 0 ) { msg_Err( p_dec, "--invmem-width and --invmem-height must be > 0" ); goto error; } psz_tmp = var_CreateGetString( p_dec, "invmem-lock" ); p_sys->pf_lock = (void * (*) (void *))(intptr_t)atoll( psz_tmp ); free( psz_tmp ); psz_tmp = var_CreateGetString( p_dec, "invmem-unlock" ); p_sys->pf_unlock = (void (*) (void *))(intptr_t)atoll( psz_tmp ); free( psz_tmp ); psz_tmp = var_CreateGetString( p_dec, "invmem-data" ); p_sys->p_data = (void *)(intptr_t)atoll( psz_tmp ); free( psz_tmp ); if( !p_sys->pf_lock || !p_sys->pf_unlock ) { msg_Err( p_dec, "Invalid lock or unlock callbacks" ); goto error; } if ( chromaStr == NULL ) { msg_Err( p_dec, "Invalid invmem-chroma string." ); goto error; } const vlc_fourcc_t chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, chromaStr ); if ( !chroma ) { msg_Err( p_dec, "invmem-chroma should be 4 characters long." ); goto error; } /* Set output properties */ switch (chroma) { case VLC_CODEC_RGB15: p_dec->fmt_out.video.i_rmask = 0x001f; p_dec->fmt_out.video.i_gmask = 0x03e0; p_dec->fmt_out.video.i_bmask = 0x7c00; pitch = p_sys->i_width * 2; break; case VLC_CODEC_RGB16: p_dec->fmt_out.video.i_rmask = 0x001f; p_dec->fmt_out.video.i_gmask = 0x07e0; p_dec->fmt_out.video.i_bmask = 0xf800; pitch = p_sys->i_width * 2; break; case VLC_CODEC_RGB24: p_dec->fmt_out.video.i_rmask = 0xff0000; p_dec->fmt_out.video.i_gmask = 0x00ff00; p_dec->fmt_out.video.i_bmask = 0x0000ff; pitch = p_sys->i_width * 3; break; case VLC_CODEC_RGB32: p_dec->fmt_out.video.i_rmask = 0xff0000; p_dec->fmt_out.video.i_gmask = 0x00ff00; p_dec->fmt_out.video.i_bmask = 0x0000ff; pitch = p_sys->i_width * 4; break; default: p_dec->fmt_out.video.i_rmask = 0; p_dec->fmt_out.video.i_gmask = 0; p_dec->fmt_out.video.i_bmask = 0; pitch = 0; msg_Warn( p_dec, "Unknown chroma %s", chromaStr ); goto error; } free( chromaStr ); p_dec->fmt_out.i_codec = chroma; p_dec->fmt_out.video.i_width = p_dec->p_sys->i_width; p_dec->fmt_out.video.i_height = p_dec->p_sys->i_height; p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR * p_dec->p_sys->i_width / p_dec->p_sys->i_height; p_dec->fmt_out.i_cat = VIDEO_ES; p_sys->i_pitch = pitch; /* Set callbacks */ p_dec->pf_decode_video = DecodeBlock; return VLC_SUCCESS; error: free( p_sys ); free( chromaStr ); return VLC_EGENERIC; }
static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* Allocate instance and initialize some members */ vd->sys = sys = malloc(sizeof(*sys)); if (!sys) return VLC_ENOMEM; sys->is_first = false; sys->is_yuv4mpeg2 = var_CreateGetBool(vd, CFG_PREFIX "yuv4mpeg2"); sys->pool = NULL; /* */ char *psz_fcc = var_CreateGetNonEmptyString(vd, CFG_PREFIX "chroma"); const vlc_fourcc_t requested_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc); free(psz_fcc); const vlc_fourcc_t chroma = requested_chroma ? requested_chroma : VLC_CODEC_I420; if (sys->is_yuv4mpeg2) { switch (chroma) { case VLC_CODEC_YV12: case VLC_CODEC_I420: case VLC_CODEC_J420: break; default: msg_Err(vd, "YUV4MPEG2 mode needs chroma YV12 not %4.4s as requested", (char *)&chroma); free(sys); return VLC_EGENERIC; } } msg_Dbg(vd, "Using chroma %4.4s", (char *)&chroma); /* */ char *name = var_CreateGetNonEmptyString(vd, CFG_PREFIX "file"); if (!name) { msg_Err(vd, "Empty file name"); free(sys); return VLC_EGENERIC; } sys->f = vlc_fopen(name, "wb"); if (!sys->f) { msg_Err(vd, "Failed to open %s", name); free(name); free(sys); return VLC_EGENERIC; } msg_Dbg(vd, "Writing data to %s", name); free(name); /* */ video_format_t fmt = vd->fmt; fmt.i_chroma = chroma; video_format_FixRgb(&fmt); /* */ vout_display_info_t info = vd->info; info.has_hide_mouse = true; /* */ vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = Manage; vout_display_SendEventFullscreen(vd, false); return VLC_SUCCESS; }
/***************************************************************************** * Open: allocates video thread ***************************************************************************** * This function allocates and initializes a vout method. *****************************************************************************/ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys = malloc(sizeof(*sys)); if (unlikely(!sys)) return VLC_ENOMEM; /* Get the callbacks */ vlc_format_cb setup = var_InheritAddress(vd, "vmem-setup"); sys->lock = var_InheritAddress(vd, "vmem-lock"); if (sys->lock == NULL) { msg_Err(vd, "missing lock callback"); free(sys); return VLC_EGENERIC; } sys->unlock = var_InheritAddress(vd, "vmem-unlock"); sys->display = var_InheritAddress(vd, "vmem-display"); sys->cleanup = var_InheritAddress(vd, "vmem-cleanup"); sys->opaque = var_InheritAddress(vd, "vmem-data"); sys->pool = NULL; /* Define the video format */ video_format_t fmt = vd->fmt; if (setup != NULL) { char chroma[5]; memcpy(chroma, &fmt.i_chroma, 4); chroma[4] = '\0'; memset(sys->pitches, 0, sizeof(sys->pitches)); memset(sys->lines, 0, sizeof(sys->lines)); sys->count = setup(&sys->opaque, chroma, &fmt.i_width, &fmt.i_height, sys->pitches, sys->lines); if (sys->count == 0) { msg_Err(vd, "video format setup failure (no pictures)"); free(sys); return VLC_EGENERIC; } fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma); } else { char *chroma = var_InheritString(vd, "vmem-chroma"); fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma); free(chroma); fmt.i_width = var_InheritInteger(vd, "vmem-width"); fmt.i_height = var_InheritInteger(vd, "vmem-height"); sys->pitches[0] = var_InheritInteger(vd, "vmem-pitch"); sys->lines[0] = fmt.i_height; for (size_t i = 1; i < PICTURE_PLANE_MAX; i++) { sys->pitches[i] = sys->pitches[0]; sys->lines[i] = sys->lines[0]; } sys->count = 1; sys->cleanup = NULL; } if (!fmt.i_chroma) { msg_Err(vd, "vmem-chroma should be 4 characters long"); free(sys); return VLC_EGENERIC; } /* Define the bitmasks */ switch (fmt.i_chroma) { case VLC_CODEC_RGB15: fmt.i_rmask = 0x001f; fmt.i_gmask = 0x03e0; fmt.i_bmask = 0x7c00; break; case VLC_CODEC_RGB16: fmt.i_rmask = 0x001f; fmt.i_gmask = 0x07e0; fmt.i_bmask = 0xf800; break; case VLC_CODEC_RGB24: case VLC_CODEC_RGB32: fmt.i_rmask = 0xff0000; fmt.i_gmask = 0x00ff00; fmt.i_bmask = 0x0000ff; break; default: fmt.i_rmask = 0; fmt.i_gmask = 0; fmt.i_bmask = 0; break; } /* */ vout_display_info_t info = vd->info; info.has_hide_mouse = true; /* */ vd->sys = sys; vd->fmt = fmt; vd->info = info; vd->pool = Pool; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = NULL; /* */ vout_display_SendEventFullscreen(vd, false); vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, false); return VLC_SUCCESS; }
/** * It opens an imem access_demux. */ static int OpenDemux(vlc_object_t *object) { demux_t *demux = (demux_t *)object; imem_sys_t *sys; if (OpenCommon(object, &sys, demux->psz_path)) return VLC_EGENERIC; /* ES format */ es_format_t fmt; es_format_Init(&fmt, UNKNOWN_ES, 0); fmt.i_id = var_InheritInteger(object, "imem-id"); fmt.i_group = var_InheritInteger(object, "imem-group"); char *tmp = var_InheritString(object, "imem-codec"); if (tmp) fmt.i_codec = vlc_fourcc_GetCodecFromString(UNKNOWN_ES, tmp); free(tmp); const int cat = var_InheritInteger(object, "imem-cat"); switch (cat) { case 1: { fmt.i_cat = AUDIO_ES; fmt.audio.i_channels = var_InheritInteger(object, "imem-channels"); fmt.audio.i_rate = var_InheritInteger(object, "imem-samplerate"); msg_Dbg(object, "Audio %4.4s %d channels %d Hz", (const char *)&fmt.i_codec, fmt.audio.i_channels, fmt.audio.i_rate); break; } case 2: { fmt.i_cat = VIDEO_ES; fmt.video.i_width = var_InheritInteger(object, "imem-width"); fmt.video.i_height = var_InheritInteger(object, "imem-height"); unsigned num, den; if (!var_InheritRational(object, &num, &den, "imem-dar") && num > 0 && den > 0) { if (fmt.video.i_width > 0 && fmt.video.i_height > 0) { fmt.video.i_sar_num = num * fmt.video.i_height; fmt.video.i_sar_den = den * fmt.video.i_width; } } if (!var_InheritRational(object, &num, &den, "imem-fps") && num > 0 && den > 0) { fmt.video.i_frame_rate = num; fmt.video.i_frame_rate_base = den; } msg_Dbg(object, "Video %4.4s %dx%d SAR %d:%d frame rate %u/%u", (const char *)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height, fmt.video.i_sar_num, fmt.video.i_sar_den, fmt.video.i_frame_rate, fmt.video.i_frame_rate_base); break; } case 3: { fmt.i_cat = SPU_ES; fmt.subs.spu.i_original_frame_width = var_InheritInteger(object, "imem-width"); fmt.subs.spu.i_original_frame_height = var_InheritInteger(object, "imem-height"); msg_Dbg(object, "Subtitle %4.4s", (const char *)&fmt.i_codec); break; } default: if (cat != 4) msg_Err(object, "Invalid ES category"); es_format_Clean(&fmt); CloseCommon(sys); return VLC_EGENERIC; } fmt.psz_language = var_InheritString(object, "imem-language"); sys->es = es_out_Add(demux->out, &fmt); es_format_Clean(&fmt); if (!sys->es) { CloseCommon(sys); return VLC_EGENERIC; } /* */ demux->pf_control = ControlDemux; demux->pf_demux = Demux; demux->p_sys = (demux_sys_t*)sys; demux->info.i_update = 0; demux->info.i_title = 0; demux->info.i_seekpoint = 0; return VLC_SUCCESS; }
/** * This function initializes SDL vout method. */ static int Open(vlc_object_t *object) { vout_display_t *vd = (vout_display_t *)object; vout_display_sys_t *sys; /* XXX: check for conflicts with the SDL audio output */ vlc_mutex_lock(&sdl_lock); /* Check if SDL video module has been initialized */ if (SDL_WasInit(SDL_INIT_VIDEO) != 0) { vlc_mutex_unlock(&sdl_lock); return VLC_EGENERIC; } vd->sys = sys = calloc(1, sizeof(*sys)); if (!sys) { vlc_mutex_unlock(&sdl_lock); return VLC_ENOMEM; } #ifdef HAVE_SETENV char *psz_driver = var_CreateGetNonEmptyString(vd, "sdl-video-driver"); if (psz_driver) { setenv("SDL_VIDEODRIVER", psz_driver, 1); free(psz_driver); } #endif /* */ int sdl_flags = SDL_INIT_VIDEO; #ifndef WIN32 /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/ sdl_flags |= SDL_INIT_EVENTTHREAD; #endif #ifndef NDEBUG /* In debug mode you may want vlc to dump a core instead of staying stuck */ sdl_flags |= SDL_INIT_NOPARACHUTE; #endif /* Initialize library */ if (SDL_Init(sdl_flags) < 0) { vlc_mutex_unlock(&sdl_lock); msg_Err(vd, "cannot initialize SDL (%s)", SDL_GetError()); free(sys); return VLC_EGENERIC; } vlc_mutex_unlock(&sdl_lock); /* Translate keys into unicode */ SDL_EnableUNICODE(1); /* Get the desktop resolution */ /* FIXME: SDL has a problem with virtual desktop */ sys->desktop_width = SDL_GetVideoInfo()->current_w; sys->desktop_height = SDL_GetVideoInfo()->current_h; /* */ video_format_t fmt = vd->fmt; /* */ vout_display_info_t info = vd->info; /* Set main window's size */ int display_width; int display_height; if (vd->cfg->is_fullscreen) { display_width = sys->desktop_width; display_height = sys->desktop_height; } else { display_width = vd->cfg->display.width; display_height = vd->cfg->display.height; } /* Initialize flags and cursor */ sys->display_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF; sys->display_flags |= vd->cfg->is_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE; sys->display_bpp = SDL_VideoModeOK(display_width, display_height, 16, sys->display_flags); if (sys->display_bpp == 0) { msg_Err(vd, "no video mode available"); goto error; } sys->display = SDL_SetVideoMode(display_width, display_height, sys->display_bpp, sys->display_flags); if (!sys->display) { msg_Err(vd, "cannot set video mode"); goto error; } /* We keep the surface locked forever */ SDL_LockSurface(sys->display); /* */ vlc_fourcc_t forced_chroma = 0; char *psz_chroma = var_CreateGetNonEmptyString(vd, "sdl-chroma"); if (psz_chroma) { forced_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_chroma); if (forced_chroma) msg_Dbg(vd, "Forcing chroma to 0x%.8x (%4.4s)", forced_chroma, (const char*)&forced_chroma); free(psz_chroma); } /* Try to open an overlay if requested */ sys->overlay = NULL; const bool is_overlay = var_CreateGetBool(vd, "overlay"); if (is_overlay) { static const struct { vlc_fourcc_t vlc; uint32_t sdl; } vlc_to_sdl[] = { { VLC_CODEC_YV12, SDL_YV12_OVERLAY }, { VLC_CODEC_I420, SDL_IYUV_OVERLAY }, { VLC_CODEC_YUYV, SDL_YUY2_OVERLAY }, { VLC_CODEC_UYVY, SDL_UYVY_OVERLAY }, { VLC_CODEC_YVYU, SDL_YVYU_OVERLAY }, { 0, 0 } }; const vlc_fourcc_t forced_chromas[] = { forced_chroma, 0 }; const vlc_fourcc_t *fallback_chromas = vlc_fourcc_GetYUVFallback(fmt.i_chroma); const vlc_fourcc_t *chromas = forced_chroma ? forced_chromas : fallback_chromas; for (int pass = forced_chroma ? 1 : 0; pass < 2 && !sys->overlay; pass++) { for (int i = 0; chromas[i] != 0; i++) { const vlc_fourcc_t vlc = chromas[i]; uint32_t sdl = 0; for (int j = 0; vlc_to_sdl[j].vlc != 0 && !sdl; j++) { if (vlc_to_sdl[j].vlc == vlc) sdl = vlc_to_sdl[j].sdl; } if (!sdl) continue; sys->overlay = SDL_CreateYUVOverlay(fmt.i_width, fmt.i_height, sdl, sys->display); if (sys->overlay && !sys->overlay->hw_overlay && pass == 0) { /* Ignore non hardware overlay surface in first pass */ SDL_FreeYUVOverlay(sys->overlay); sys->overlay = NULL; } if (sys->overlay) { /* We keep the surface locked forever */ SDL_LockYUVOverlay(sys->overlay); fmt.i_chroma = vlc; sys->is_uv_swapped = vlc_fourcc_AreUVPlanesSwapped(fmt.i_chroma, vd->fmt.i_chroma); if (sys->is_uv_swapped) fmt.i_chroma = vd->fmt.i_chroma; break; } } } } else { msg_Warn(vd, "SDL overlay disabled by the user"); } /* */ vout_display_cfg_t place_cfg = *vd->cfg; place_cfg.display.width = display_width; place_cfg.display.height = display_height; vout_display_PlacePicture(&sys->place, &vd->source, &place_cfg, !sys->overlay); /* If no overlay, fallback to software output */ if (!sys->overlay) { /* */ switch (sys->display->format->BitsPerPixel) { case 8: fmt.i_chroma = VLC_CODEC_RGB8; break; case 15: fmt.i_chroma = VLC_CODEC_RGB15; break; case 16: fmt.i_chroma = VLC_CODEC_RGB16; break; case 24: fmt.i_chroma = VLC_CODEC_RGB24; break; case 32: fmt.i_chroma = VLC_CODEC_RGB32; break; default: msg_Err(vd, "unknown screen depth %i", sys->display->format->BitsPerPixel); goto error; } /* All we have is an RGB image with square pixels */ fmt.i_width = display_width; fmt.i_height = display_height; fmt.i_rmask = sys->display->format->Rmask; fmt.i_gmask = sys->display->format->Gmask; fmt.i_bmask = sys->display->format->Bmask; info.has_pictures_invalid = true; } if (vd->cfg->display.title) SDL_WM_SetCaption(vd->cfg->display.title, vd->cfg->display.title); else if (!sys->overlay) SDL_WM_SetCaption(VOUT_TITLE " (software RGB SDL output)", VOUT_TITLE " (software RGB SDL output)"); else if (sys->overlay->hw_overlay) SDL_WM_SetCaption(VOUT_TITLE " (hardware YUV SDL output)", VOUT_TITLE " (hardware YUV SDL output)"); else SDL_WM_SetCaption(VOUT_TITLE " (software YUV SDL output)", VOUT_TITLE " (software YUV SDL output)"); /* Setup events */ SDL_EventState(SDL_KEYUP, SDL_IGNORE); /* ignore keys up */ /* Setup vout_display now that everything is fine */ vd->fmt = fmt; vd->info = info; vd->get = Get; vd->prepare = NULL; vd->display = Display; vd->control = Control; vd->manage = Manage; /* */ vout_display_SendEventDisplaySize(vd, display_width, display_height, vd->cfg->is_fullscreen); return VLC_SUCCESS; error: msg_Err(vd, "cannot set up SDL (%s)", SDL_GetError()); if (sys->display) { SDL_UnlockSurface(sys->display); SDL_FreeSurface(sys->display); } vlc_mutex_lock(&sdl_lock); SDL_QuitSubSystem(SDL_INIT_VIDEO); vlc_mutex_unlock(&sdl_lock); free(sys); return VLC_EGENERIC; }
/***************************************************************************** * OpenDecoder: probe the decoder and return score *****************************************************************************/ static int OpenDecoder( vlc_object_t *p_this ) { decoder_t *p_dec = (decoder_t*)p_this; vlc_value_t val; image_handler_t *p_handler; video_format_t fmt_in, fmt_out; picture_t *p_image; char *psz_file, *psz_chroma; bool b_keep_ar; int i_aspect = 0; if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e') ) { return VLC_EGENERIC; } p_dec->p_sys = calloc( 1, sizeof( *p_dec->p_sys ) ); if( !p_dec->p_sys ) return VLC_ENOMEM; psz_file = var_CreateGetNonEmptyStringCommand( p_dec, "fake-file" ); if( !psz_file ) { msg_Err( p_dec, "specify a file with --fake-file=..." ); free( p_dec->p_sys ); return VLC_EGENERIC; } var_AddCallback( p_dec, "fake-file", FakeCallback, p_dec ); memset( &fmt_in, 0, sizeof(fmt_in) ); memset( &fmt_out, 0, sizeof(fmt_out) ); val.i_int = var_CreateGetIntegerCommand( p_dec, "fake-file-reload" ); if( val.i_int > 0) { p_dec->p_sys->b_reload = true; p_dec->p_sys->i_reload = (mtime_t)(val.i_int * 1000000); p_dec->p_sys->i_next = (mtime_t)(p_dec->p_sys->i_reload + mdate()); } var_AddCallback( p_dec, "fake-file-reload", FakeCallback , p_dec ); psz_chroma = var_CreateGetString( p_dec, "fake-chroma" ); fmt_out.i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); if( !fmt_out.i_chroma ) { msg_Warn( p_dec, "Invalid chroma (%s). Using I420.", psz_chroma ); fmt_out.i_chroma = VLC_CODEC_I420; } free( psz_chroma ); var_Create( p_dec, "fake-keep-ar", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-keep-ar", &val ); b_keep_ar = val.b_bool; var_Create( p_dec, "fake-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_dec, "fake-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); var_Create( p_dec, "fake-aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-aspect-ratio", &val ); if ( val.psz_string ) { char *psz_parser = strchr( val.psz_string, ':' ); if( psz_parser ) { *psz_parser++ = '\0'; i_aspect = atoi( val.psz_string ) * VOUT_ASPECT_FACTOR / atoi( psz_parser ); } free( val.psz_string ); } if ( !b_keep_ar ) { var_Get( p_dec, "fake-width", &val ); fmt_out.i_width = val.i_int; var_Get( p_dec, "fake-height", &val ); fmt_out.i_height = val.i_int; } p_handler = image_HandlerCreate( p_dec ); p_image = image_ReadUrl( p_handler, psz_file, &fmt_in, &fmt_out ); image_HandlerDelete( p_handler ); if ( p_image == NULL ) { msg_Err( p_dec, "unable to read image file %s", psz_file ); free( psz_file ); free( p_dec->p_sys ); return VLC_EGENERIC; } msg_Dbg( p_dec, "file %s loaded successfully", psz_file ); free( psz_file ); if ( b_keep_ar ) { picture_t *p_old = p_image; int i_width, i_height; var_Get( p_dec, "fake-width", &val ); i_width = val.i_int; var_Get( p_dec, "fake-height", &val ); i_height = val.i_int; if ( i_width && i_height ) { int i_image_ar = fmt_out.i_width * VOUT_ASPECT_FACTOR / fmt_out.i_height; int i_region_ar = i_width * VOUT_ASPECT_FACTOR / i_height; fmt_in = fmt_out; if ( i_aspect == i_image_ar ) { fmt_out.i_width = i_width; fmt_out.i_height = i_height; } else if ( i_image_ar > i_region_ar ) { fmt_out.i_width = i_width; fmt_out.i_height = i_width * VOUT_ASPECT_FACTOR / i_image_ar; i_aspect = i_image_ar; } else { fmt_out.i_height = i_height; fmt_out.i_width = i_height * i_image_ar / VOUT_ASPECT_FACTOR; i_aspect = i_image_ar; } p_handler = image_HandlerCreate( p_dec ); p_image = image_Convert( p_handler, p_old, &fmt_in, &fmt_out ); image_HandlerDelete( p_handler ); if ( p_image == NULL ) { msg_Warn( p_dec, "couldn't load resizing module" ); p_image = p_old; fmt_out = fmt_in; } else { picture_Release( p_old ); } } } if ( i_aspect ) { fmt_out.i_aspect = i_aspect; } else { fmt_out.i_aspect = fmt_out.i_width * VOUT_ASPECT_FACTOR / fmt_out.i_height; } var_Create( p_dec, "fake-deinterlace", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-deinterlace", &val ); if ( val.b_bool ) { picture_t *p_old = p_image; var_Create( p_dec, "fake-deinterlace-module", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Get( p_dec, "fake-deinterlace-module", &val ); p_handler = image_HandlerCreate( p_dec ); p_image = image_Filter( p_handler, p_old, &fmt_out, val.psz_string ); image_HandlerDelete( p_handler ); free( val.psz_string ); if ( p_image == NULL ) { msg_Warn( p_dec, "couldn't load deinterlace module" ); p_image = p_old; } else { picture_Release( p_old ); } } /* Set output properties */ p_dec->fmt_out.i_cat = VIDEO_ES; p_dec->fmt_out.i_codec = fmt_out.i_chroma; p_dec->fmt_out.video = fmt_out; /* Set callbacks */ p_dec->pf_decode_video = DecodeBlock; p_dec->p_sys->p_image = p_image; vlc_mutex_init( &p_dec->p_sys->lock ); return VLC_SUCCESS; }
/***************************************************************************** * Open: *****************************************************************************/ static int Open( vlc_object_t *p_this ) { sout_stream_t *p_stream = (sout_stream_t*)p_this; sout_stream_sys_t *p_sys; char *psz_string; if( !p_stream->p_next ) { msg_Err( p_stream, "cannot create chain" ); return VLC_EGENERIC; } p_sys = calloc( 1, sizeof( *p_sys ) ); p_sys->i_master_drift = 0; config_ChainParse( p_stream, SOUT_CFG_PREFIX, ppsz_sout_options, p_stream->p_cfg ); /* Audio transcoding parameters */ psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "aenc" ); p_sys->psz_aenc = NULL; p_sys->p_audio_cfg = NULL; if( psz_string && *psz_string ) { char *psz_next; psz_next = config_ChainCreate( &p_sys->psz_aenc, &p_sys->p_audio_cfg, psz_string ); free( psz_next ); } free( psz_string ); psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "acodec" ); p_sys->i_acodec = 0; if( psz_string && *psz_string ) { char fcc[5] = " \0"; memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) ); p_sys->i_acodec = vlc_fourcc_GetCodecFromString( AUDIO_ES, fcc ); msg_Dbg( p_stream, "Checking codec mapping for %s got %4.4s ", fcc, (char*)&p_sys->i_acodec); } free( psz_string ); p_sys->psz_alang = var_GetNonEmptyString( p_stream, SOUT_CFG_PREFIX "alang" ); p_sys->i_abitrate = var_GetInteger( p_stream, SOUT_CFG_PREFIX "ab" ); if( p_sys->i_abitrate < 4000 ) p_sys->i_abitrate *= 1000; p_sys->i_sample_rate = var_GetInteger( p_stream, SOUT_CFG_PREFIX "samplerate" ); p_sys->i_channels = var_GetInteger( p_stream, SOUT_CFG_PREFIX "channels" ); if( p_sys->i_acodec ) { if( ( p_sys->i_acodec == VLC_CODEC_MP3 || p_sys->i_acodec == VLC_CODEC_MP2 || p_sys->i_acodec == VLC_CODEC_MPGA ) && p_sys->i_channels > 2 ) { msg_Warn( p_stream, "%d channels invalid for mp2/mp3, forcing to 2", p_sys->i_channels ); p_sys->i_channels = 2; } msg_Dbg( p_stream, "codec audio=%4.4s %dHz %d channels %dKb/s", (char *)&p_sys->i_acodec, p_sys->i_sample_rate, p_sys->i_channels, p_sys->i_abitrate / 1000 ); } psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "afilter" ); if( psz_string && *psz_string ) p_sys->psz_af = strdup( psz_string ); else p_sys->psz_af = NULL; free( psz_string ); /* Video transcoding parameters */ psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "venc" ); p_sys->psz_venc = NULL; p_sys->p_video_cfg = NULL; if( psz_string && *psz_string ) { char *psz_next; psz_next = config_ChainCreate( &p_sys->psz_venc, &p_sys->p_video_cfg, psz_string ); free( psz_next ); } free( psz_string ); psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "vcodec" ); p_sys->i_vcodec = 0; if( psz_string && *psz_string ) { char fcc[5] = " \0"; memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) ); p_sys->i_vcodec = vlc_fourcc_GetCodecFromString( VIDEO_ES, fcc ); msg_Dbg( p_stream, "Checking video codec mapping for %s got %4.4s ", fcc, (char*)&p_sys->i_vcodec); } free( psz_string ); p_sys->i_vbitrate = var_GetInteger( p_stream, SOUT_CFG_PREFIX "vb" ); if( p_sys->i_vbitrate < 16000 ) p_sys->i_vbitrate *= 1000; p_sys->f_scale = var_GetFloat( p_stream, SOUT_CFG_PREFIX "scale" ); p_sys->b_master_sync = var_InheritURational( p_stream, &p_sys->fps_num, &p_sys->fps_den, SOUT_CFG_PREFIX "fps" ) == VLC_SUCCESS; p_sys->i_width = var_GetInteger( p_stream, SOUT_CFG_PREFIX "width" ); p_sys->i_height = var_GetInteger( p_stream, SOUT_CFG_PREFIX "height" ); p_sys->i_maxwidth = var_GetInteger( p_stream, SOUT_CFG_PREFIX "maxwidth" ); p_sys->i_maxheight = var_GetInteger( p_stream, SOUT_CFG_PREFIX "maxheight" ); psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "vfilter" ); if( psz_string && *psz_string ) p_sys->psz_vf2 = strdup(psz_string ); else p_sys->psz_vf2 = NULL; free( psz_string ); p_sys->b_deinterlace = var_GetBool( p_stream, SOUT_CFG_PREFIX "deinterlace" ); psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "deinterlace-module" ); p_sys->psz_deinterlace = NULL; p_sys->p_deinterlace_cfg = NULL; if( psz_string && *psz_string ) { char *psz_next; psz_next = config_ChainCreate( &p_sys->psz_deinterlace, &p_sys->p_deinterlace_cfg, psz_string ); free( psz_next ); } free( psz_string ); p_sys->i_threads = var_GetInteger( p_stream, SOUT_CFG_PREFIX "threads" ); p_sys->b_high_priority = var_GetBool( p_stream, SOUT_CFG_PREFIX "high-priority" ); if( p_sys->i_vcodec ) { msg_Dbg( p_stream, "codec video=%4.4s %dx%d scaling: %f %dkb/s", (char *)&p_sys->i_vcodec, p_sys->i_width, p_sys->i_height, p_sys->f_scale, p_sys->i_vbitrate / 1000 ); } /* Disable hardware decoding by default (unlike normal playback) */ psz_string = var_CreateGetString( p_stream, "avcodec-hw" ); if( !strcasecmp( "any", psz_string ) ) var_SetString( p_stream, "avcodec-hw", "none" ); free( psz_string ); /* Subpictures transcoding parameters */ p_sys->p_spu = NULL; p_sys->p_spu_blend = NULL; p_sys->psz_senc = NULL; p_sys->p_spu_cfg = NULL; p_sys->i_scodec = 0; psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "senc" ); if( psz_string && *psz_string ) { char *psz_next; psz_next = config_ChainCreate( &p_sys->psz_senc, &p_sys->p_spu_cfg, psz_string ); free( psz_next ); } free( psz_string ); psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "scodec" ); if( psz_string && *psz_string ) { char fcc[5] = " \0"; memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) ); p_sys->i_scodec = vlc_fourcc_GetCodecFromString( SPU_ES, fcc ); msg_Dbg( p_stream, "Checking spu codec mapping for %s got %4.4s ", fcc, (char*)&p_sys->i_scodec); } free( psz_string ); if( p_sys->i_scodec ) { msg_Dbg( p_stream, "codec spu=%4.4s", (char *)&p_sys->i_scodec ); } p_sys->b_soverlay = var_GetBool( p_stream, SOUT_CFG_PREFIX "soverlay" ); psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "sfilter" ); if( psz_string && *psz_string ) { p_sys->p_spu = spu_Create( p_stream ); if( p_sys->p_spu ) spu_ChangeSources( p_sys->p_spu, psz_string ); } free( psz_string ); /* OSD menu transcoding parameters */ p_sys->psz_osdenc = NULL; p_sys->p_osd_cfg = NULL; p_sys->i_osdcodec = 0; p_sys->b_osd = var_GetBool( p_stream, SOUT_CFG_PREFIX "osd" ); if( p_sys->b_osd ) { char *psz_next; psz_next = config_ChainCreate( &p_sys->psz_osdenc, &p_sys->p_osd_cfg, "dvbsub" ); free( psz_next ); p_sys->i_osdcodec = VLC_CODEC_YUVP; msg_Dbg( p_stream, "codec osd=%4.4s", (char *)&p_sys->i_osdcodec ); if( !p_sys->p_spu ) { p_sys->p_spu = spu_Create( p_stream ); if( p_sys->p_spu ) spu_ChangeSources( p_sys->p_spu, "osdmenu" ); } else { spu_ChangeSources( p_sys->p_spu, "osdmenu" ); } } p_stream->pf_add = Add; p_stream->pf_del = Del; p_stream->pf_send = Send; p_stream->p_sys = p_sys; return VLC_SUCCESS; }
static int Open(vlc_object_t *p_this) { vout_display_t *vd = (vout_display_t*)p_this; vout_display_sys_t *sys; video_format_t sub_fmt; if (vout_display_IsWindowed(vd)) return VLC_EGENERIC; /* XXX: android_window use a surface created by VideoPlayerActivity to * alloc pictures. Don't try to open the vout if this activity is not * created. This need to be replaced by something like var_CreateGetAddress * (vd, "drawable-android") in the future. */ if (!jni_IsVideoPlayerActivityCreated()) return VLC_EGENERIC; /* Allocate structure */ vd->sys = sys = (struct vout_display_sys_t*)calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; sys->p_library = LoadNativeWindowAPI(&sys->anw); if (!sys->p_library) { msg_Err(vd, "Could not initialize NativeWindow API."); goto error; } #ifdef USE_ANWP if (LoadNativeWindowPrivAPI(&sys->anwp) == 0) sys->b_has_anwp = true; else msg_Warn(vd, "Could not initialize NativeWindow Priv API."); #endif sys->i_display_width = vd->cfg->display.width; sys->i_display_height = vd->cfg->display.height; if (vd->fmt.i_chroma != VLC_CODEC_ANDROID_OPAQUE) { /* Setup chroma */ char *psz_fcc = var_InheritString(vd, CFG_PREFIX "chroma"); if (psz_fcc) { vd->fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc); free(psz_fcc); } else vd->fmt.i_chroma = VLC_CODEC_RGB32; switch(vd->fmt.i_chroma) { case VLC_CODEC_YV12: /* avoid swscale usage by asking for I420 instead since the * vout already has code to swap the buffers */ vd->fmt.i_chroma = VLC_CODEC_I420; case VLC_CODEC_I420: break; case VLC_CODEC_RGB16: case VLC_CODEC_RGB32: case VLC_CODEC_RGBA: SetRGBMask(&vd->fmt); video_format_FixRgb(&vd->fmt); break; default: goto error; } } sys->p_window = AndroidWindow_New(sys, &vd->fmt, true); if (!sys->p_window) goto error; if (SetupWindowSurface(sys, 0) != 0) goto error; /* use software rotation if we don't use private anw */ if (!sys->p_window->b_opaque && !sys->p_window->b_use_priv) video_format_ApplyRotation(&vd->fmt, &vd->fmt); msg_Dbg(vd, "using %s", sys->p_window->b_opaque ? "opaque" : (sys->p_window->b_use_priv ? "ANWP" : "ANW")); video_format_ApplyRotation(&sub_fmt, &vd->fmt); sub_fmt.i_chroma = subpicture_chromas[0]; SetRGBMask(&sub_fmt); video_format_FixRgb(&sub_fmt); sys->p_sub_window = AndroidWindow_New(sys, &sub_fmt, false); if (!sys->p_sub_window) goto error; FixSubtitleFormat(sys); sys->i_sub_last_order = -1; /* Export the subpicture capability of this vout. */ vd->info.subpicture_chromas = subpicture_chromas; /* Setup vout_display */ vd->pool = Pool; vd->prepare = Prepare; vd->display = Display; vd->control = Control; vd->manage = Manage; /* Fix initial state */ vout_display_SendEventFullscreen(vd, true); SendEventDisplaySize(vd); return VLC_SUCCESS; error: Close(p_this); return VLC_ENOMEM; }
static int Open(vlc_object_t *p_this) { vout_display_t *vd = (vout_display_t*)p_this; vout_display_sys_t *sys; video_format_t sub_fmt; if (vout_display_IsWindowed(vd)) return VLC_EGENERIC; /* Allocate structure */ vd->sys = sys = (struct vout_display_sys_t*)calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; sys->p_awh = AWindowHandler_new(p_this); if (!sys->p_awh) { free(sys); msg_Err(vd, "AWindowHandler_new failed"); return VLC_EGENERIC; } sys->anw = AWindowHandler_getANativeWindowAPI(sys->p_awh); #ifdef USE_ANWP sys->anwp = AWindowHandler_getANativeWindowPrivAPI(sys->p_awh); if (!sys->anwp) msg_Warn(vd, "Could not initialize NativeWindow Priv API."); #endif sys->i_display_width = vd->cfg->display.width; sys->i_display_height = vd->cfg->display.height; if (vd->fmt.i_chroma != VLC_CODEC_ANDROID_OPAQUE) { /* Setup chroma */ char *psz_fcc = var_InheritString(vd, CFG_PREFIX "chroma"); if (psz_fcc) { vd->fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc); free(psz_fcc); } else vd->fmt.i_chroma = VLC_CODEC_RGB32; switch(vd->fmt.i_chroma) { case VLC_CODEC_YV12: /* avoid swscale usage by asking for I420 instead since the * vout already has code to swap the buffers */ vd->fmt.i_chroma = VLC_CODEC_I420; case VLC_CODEC_I420: break; case VLC_CODEC_RGB16: case VLC_CODEC_RGB32: case VLC_CODEC_RGBA: SetRGBMask(&vd->fmt); video_format_FixRgb(&vd->fmt); break; default: goto error; } } sys->p_window = AndroidWindow_New(vd, &vd->fmt, AWindow_Video, true); if (!sys->p_window) goto error; if (AndroidWindow_Setup(sys, sys->p_window, 0) != 0) goto error; /* use software rotation if we don't use private anw */ if (!sys->p_window->b_opaque && !sys->p_window->b_use_priv) video_format_ApplyRotation(&vd->fmt, &vd->fmt); msg_Dbg(vd, "using %s", sys->p_window->b_opaque ? "opaque" : (sys->p_window->b_use_priv ? "ANWP" : "ANW")); video_format_ApplyRotation(&sub_fmt, &vd->fmt); sub_fmt.i_chroma = subpicture_chromas[0]; SetRGBMask(&sub_fmt); video_format_FixRgb(&sub_fmt); sys->p_sub_window = AndroidWindow_New(vd, &sub_fmt, AWindow_Subtitles, false); if (sys->p_sub_window) { FixSubtitleFormat(sys); sys->i_sub_last_order = -1; /* Export the subpicture capability of this vout. */ vd->info.subpicture_chromas = subpicture_chromas; } /* Setup vout_display */ vd->pool = Pool; vd->prepare = Prepare; vd->display = Display; vd->control = Control; vd->manage = Manage; /* Fix initial state */ vout_display_SendEventFullscreen(vd, true); SendEventDisplaySize(vd); return VLC_SUCCESS; error: Close(p_this); return VLC_ENOMEM; }
static int Open(vlc_object_t *p_this) { vout_display_t *vd = (vout_display_t *)p_this; video_format_t fmt; video_format_ApplyRotation(&fmt, &vd->fmt); if (fmt.i_chroma == VLC_CODEC_ANDROID_OPAQUE) return VLC_EGENERIC; if (vout_display_IsWindowed(vd)) return VLC_EGENERIC; /* Allocate structure */ vout_display_sys_t *sys = (struct vout_display_sys_t*) calloc(1, sizeof(*sys)); if (!sys) goto error; /* */ sys->p_library = InitLibrary(sys); if (!sys->p_library) { msg_Err(vd, "Could not initialize libandroid.so/libui.so/libgui.so/libsurfaceflinger_client.so!"); goto error; } /* Setup chroma */ char *psz_fcc = var_InheritString(vd, CFG_PREFIX "chroma"); if( psz_fcc ) { fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc); free(psz_fcc); } else fmt.i_chroma = VLC_CODEC_RGB32; switch(fmt.i_chroma) { case VLC_CODEC_RGB16: fmt.i_bmask = 0x0000001f; fmt.i_gmask = 0x000007e0; fmt.i_rmask = 0x0000f800; break; case VLC_CODEC_YV12: case VLC_CODEC_I420: fmt.i_chroma = VLC_CODEC_RGB32; case VLC_CODEC_RGB32: fmt.i_rmask = 0x000000ff; fmt.i_gmask = 0x0000ff00; fmt.i_bmask = 0x00ff0000; break; default: return VLC_EGENERIC; } video_format_FixRgb(&fmt); msg_Dbg(vd, "Pixel format %4.4s", (char*)&fmt.i_chroma); sys->i_android_hal = ChromaToAndroidHal(fmt.i_chroma); if (sys->i_android_hal == -1) goto error; sys->fmt = fmt; UpdateLayout(sys); /* Create the associated picture */ picture_sys_t *picsys = calloc(1, sizeof(picture_sys_t)); if (unlikely(picsys == NULL)) goto error; picsys->sys = sys; picture_resource_t resource = { .p_sys = picsys }; picture_t *picture = picture_NewFromResource(&fmt, &resource); if (!picture) { free(picsys); goto error; } /* Wrap it into a picture pool */ picture_pool_configuration_t pool_cfg; memset(&pool_cfg, 0, sizeof(pool_cfg)); pool_cfg.picture_count = 1; pool_cfg.picture = &picture; pool_cfg.lock = AndroidLockSurface; pool_cfg.unlock = AndroidUnlockSurface; sys->pool = picture_pool_NewExtended(&pool_cfg); if (!sys->pool) { picture_Release(picture); goto error; } /* Setup vout_display */ vd->sys = sys; vd->fmt = fmt; vd->pool = Pool; vd->display = Display; vd->control = Control; vd->prepare = NULL; vd->manage = Manage; /* Fix initial state */ vout_display_SendEventFullscreen(vd, false); return VLC_SUCCESS; error: Close(p_this); return VLC_ENOMEM; }
/***************************************************************************** * Open: initializes raw audio demuxer *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; char *psz_fourcc = var_CreateGetString( p_demux, "rawaud-fourcc" ); es_format_Init( &p_sys->fmt, AUDIO_ES, vlc_fourcc_GetCodecFromString( AUDIO_ES, psz_fourcc ) ); free( psz_fourcc ); if( !p_sys->fmt.i_codec ) { msg_Err( p_demux, "rawaud-fourcc must be a 4 character string"); es_format_Clean( &p_sys->fmt ); free( p_sys ); return VLC_EGENERIC; } // get the bits per sample ratio based on codec switch( p_sys->fmt.i_codec ) { case VLC_CODEC_FL64: p_sys->fmt.audio.i_bitspersample = 64; break; case VLC_CODEC_FL32: case VLC_CODEC_S32L: case VLC_CODEC_S32B: p_sys->fmt.audio.i_bitspersample = 32; break; case VLC_CODEC_S24L: case VLC_CODEC_S24B: p_sys->fmt.audio.i_bitspersample = 24; break; case VLC_CODEC_S16L: case VLC_CODEC_S16B: p_sys->fmt.audio.i_bitspersample = 16; break; case VLC_CODEC_S8: case VLC_CODEC_U8: p_sys->fmt.audio.i_bitspersample = 8; break; default: msg_Err( p_demux, "unknown fourcc format %4.4s", (char *)&p_sys->fmt.i_codec); es_format_Clean( &p_sys->fmt ); free( p_sys ); return VLC_EGENERIC; } p_sys->fmt.psz_language = var_CreateGetString( p_demux, "rawaud-lang" ); p_sys->fmt.audio.i_channels = var_CreateGetInteger( p_demux, "rawaud-channels" ); p_sys->fmt.audio.i_rate = var_CreateGetInteger( p_demux, "rawaud-samplerate" ); if( p_sys->fmt.audio.i_rate == 0 || p_sys->fmt.audio.i_rate > 384000 ) { msg_Err( p_demux, "invalid sample rate"); es_format_Clean( &p_sys->fmt ); free( p_sys ); return VLC_EGENERIC; } if( p_sys->fmt.audio.i_channels == 0 || p_sys->fmt.audio.i_channels > 32 ) { msg_Err( p_demux, "invalid number of channels"); es_format_Clean( &p_sys->fmt ); free( p_sys ); return VLC_EGENERIC; } p_sys->fmt.i_bitrate = p_sys->fmt.audio.i_rate * p_sys->fmt.audio.i_channels * p_sys->fmt.audio.i_bitspersample; if( p_sys->fmt.i_bitrate > 50000000) { msg_Err( p_demux, "invalid bitrate"); es_format_Clean( &p_sys->fmt ); free( p_sys ); return VLC_EGENERIC; } msg_Dbg( p_demux, "format initialized: channels=%d , samplerate=%d Hz, fourcc=%4.4s, bits per sample = %d, bitrate = %d bit/s", p_sys->fmt.audio.i_channels, p_sys->fmt.audio.i_rate, (char*)&p_sys->fmt.i_codec, p_sys->fmt.audio.i_bitspersample, p_sys->fmt.i_bitrate); /* add the es */ p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt ); msg_Dbg( p_demux, "elementary stream added"); /* initialize timing */ date_Init( &p_sys->pts, p_sys->fmt.audio.i_rate, 1 ); date_Set( &p_sys->pts, VLC_TICK_0 ); /* calculate 50ms frame size/time */ p_sys->i_frame_samples = __MAX( p_sys->fmt.audio.i_rate / 20, 1 ); p_sys->i_seek_step = p_sys->fmt.audio.i_channels * ( (p_sys->fmt.audio.i_bitspersample + 7) / 8 ); p_sys->i_frame_size = p_sys->i_frame_samples * p_sys->i_seek_step; msg_Dbg( p_demux, "frame size is %d bytes ", p_sys->i_frame_size); p_demux->pf_demux = Demux; p_demux->pf_control = Control; return VLC_SUCCESS; }
/***************************************************************************** * Open: *****************************************************************************/ static int Open( vlc_object_t *p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; if (p_demux->out == NULL) return VLC_EGENERIC; p_sys = vlc_obj_calloc( p_this, 1, sizeof(demux_sys_t) ); if( !p_sys ) return VLC_ENOMEM; p_sys->f_fps = var_InheritFloat( p_demux, CFG_PREFIX "fps" ); if ( p_sys->f_fps <= 0 ) p_sys->f_fps = 1.0; p_sys->i_frame_interval = vlc_tick_rate_duration( p_sys->f_fps ); char *psz_chroma = var_InheritString( p_demux, CFG_PREFIX "chroma" ); vlc_fourcc_t i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); free( psz_chroma ); if ( !i_chroma || vlc_fourcc_IsYUV( i_chroma ) ) { msg_Err( p_demux, "Only RGB chroma are supported" ); return VLC_EGENERIC; } const vlc_chroma_description_t *p_chroma_desc = vlc_fourcc_GetChromaDescription( i_chroma ); if ( !p_chroma_desc ) { msg_Err( p_demux, "Unable to get RGB chroma description" ); return VLC_EGENERIC; } #ifdef NDEBUG rfbEnableClientLogging = FALSE; #endif p_sys->p_client = rfbGetClient( p_chroma_desc->pixel_bits / 3, // bitsPerSample 3, // samplesPerPixel p_chroma_desc->pixel_size ); // bytesPerPixel if ( ! p_sys->p_client ) { msg_Dbg( p_demux, "Unable to set up client for %s", vlc_fourcc_GetDescription( VIDEO_ES, i_chroma ) ); return VLC_EGENERIC; } msg_Dbg( p_demux, "set up client for %s %d %d %d", vlc_fourcc_GetDescription( VIDEO_ES, i_chroma ), p_chroma_desc->pixel_bits / 3, 3, p_chroma_desc->pixel_size ); p_sys->p_client->MallocFrameBuffer = mallocFrameBufferHandler; p_sys->p_client->canHandleNewFBSize = TRUE; p_sys->p_client->GetCredential = getCredentialHandler; p_sys->p_client->GetPassword = getPasswordHandler; /* VNC simple auth */ /* Set compression and quality levels */ p_sys->p_client->appData.compressLevel = var_InheritInteger( p_demux, CFG_PREFIX "compress-level" ); p_sys->p_client->appData.qualityLevel = var_InheritInteger( p_demux, CFG_PREFIX "quality-level" ); /* Parse uri params */ vlc_url_t url; vlc_UrlParse( &url, p_demux->psz_location ); if ( !EMPTY_STR(url.psz_host) ) p_sys->p_client->serverHost = strdup( url.psz_host ); else p_sys->p_client->serverHost = strdup( "localhost" ); p_sys->p_client->appData.viewOnly = TRUE; p_sys->p_client->serverPort = ( url.i_port > 0 ) ? url.i_port : 5900; msg_Dbg( p_demux, "VNC init %s host=%s port=%d", p_demux->psz_location, p_sys->p_client->serverHost, p_sys->p_client->serverPort ); vlc_UrlClean( &url ); /* make demux available for callback handlers */ rfbClientSetClientData( p_sys->p_client, DemuxThread, p_demux ); p_demux->p_sys = p_sys; if( !rfbInitClient( p_sys->p_client, NULL, NULL ) ) { msg_Err( p_demux, "can't connect to RFB server" ); return VLC_EGENERIC; } p_sys->i_starttime = vlc_tick_now(); if ( vlc_clone( &p_sys->thread, DemuxThread, p_demux, VLC_THREAD_PRIORITY_INPUT ) != VLC_SUCCESS ) { msg_Err( p_demux, "can't spawn thread" ); return VLC_EGENERIC; } p_demux->pf_demux = NULL; p_demux->pf_control = Control; return VLC_SUCCESS; }
static int Open(vlc_object_t *object) { demux_t *demux = (demux_t*)object; /* Detect the image type */ const image_format_t *img; const uint8_t *peek; int peek_size = 0; for (int i = 0; ; i++) { img = &formats[i]; if (!img->codec) return VLC_EGENERIC; if (img->detect) { if (img->detect(demux->s)) break; } else { if (peek_size < img->marker_size) peek_size = stream_Peek(demux->s, &peek, img->marker_size); if (peek_size >= img->marker_size && !memcmp(peek, img->marker, img->marker_size)) break; } } msg_Dbg(demux, "Detected image: %s", vlc_fourcc_GetDescription(VIDEO_ES, img->codec)); if( img->codec == VLC_CODEC_MXPEG ) { return VLC_EGENERIC; //let avformat demux this file } /* Load and if selected decode */ es_format_t fmt; es_format_Init(&fmt, VIDEO_ES, img->codec); fmt.video.i_chroma = fmt.i_codec; block_t *data = Load(demux); if (data && var_InheritBool(demux, "image-decode")) { char *string = var_InheritString(demux, "image-chroma"); vlc_fourcc_t chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, string); free(string); data = Decode(demux, &fmt.video, chroma, data); fmt.i_codec = fmt.video.i_chroma; } fmt.i_id = var_InheritInteger(demux, "image-id"); fmt.i_group = var_InheritInteger(demux, "image-group"); if (var_InheritURational(demux, &fmt.video.i_frame_rate, &fmt.video.i_frame_rate_base, "image-fps") || fmt.video.i_frame_rate <= 0 || fmt.video.i_frame_rate_base <= 0) { msg_Err(demux, "Invalid frame rate, using 10/1 instead"); fmt.video.i_frame_rate = 10; fmt.video.i_frame_rate_base = 1; } /* If loadind failed, we still continue to avoid mis-detection * by other demuxers. */ if (!data) msg_Err(demux, "Failed to load the image"); /* */ demux_sys_t *sys = malloc(sizeof(*sys)); if (!sys) { if (data) block_Release(data); es_format_Clean(&fmt); return VLC_ENOMEM; } sys->data = data; sys->es = es_out_Add(demux->out, &fmt); sys->duration = CLOCK_FREQ * var_InheritFloat(demux, "image-duration"); sys->is_realtime = var_InheritBool(demux, "image-realtime"); sys->pts_origin = sys->is_realtime ? mdate() : 0; sys->pts_next = VLC_TS_INVALID; date_Init(&sys->pts, fmt.video.i_frame_rate, fmt.video.i_frame_rate_base); date_Set(&sys->pts, 0); es_format_Clean(&fmt); demux->pf_demux = Demux; demux->pf_control = Control; demux->p_sys = sys; return VLC_SUCCESS; }
static int Open(vlc_object_t *p_this) { vout_display_t *vd = (vout_display_t *)p_this; vout_display_sys_t *sys; void *p_library; /* */ if (vlc_mutex_trylock(&single_instance) != 0) { msg_Err(vd, "Can't start more than one instance at a time"); return VLC_EGENERIC; } /* Allocate structure */ sys = (struct vout_display_sys_t*) calloc(1, sizeof(*sys)); if (!sys) { vlc_mutex_unlock(&single_instance); return VLC_ENOMEM; } /* */ sys->p_library = p_library = InitLibrary(sys); if (!p_library) { free(sys); msg_Err(vd, "Could not initialize libui.so/libgui.so/libsurfaceflinger_client.so!"); vlc_mutex_unlock(&single_instance); return VLC_EGENERIC; } /* Setup chroma */ video_format_t fmt = vd->fmt; char *psz_fcc = var_InheritString(vd, CFG_PREFIX "chroma"); if( psz_fcc ) { fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc); free(psz_fcc); } else fmt.i_chroma = VLC_CODEC_RGB32; switch(fmt.i_chroma) { case VLC_CODEC_YV12: /* avoid swscale usage by asking for I420 instead since the * vout already has code to swap the buffers */ fmt.i_chroma = VLC_CODEC_I420; case VLC_CODEC_I420: break; case VLC_CODEC_RGB16: fmt.i_bmask = 0x0000001f; fmt.i_gmask = 0x000007e0; fmt.i_rmask = 0x0000f800; break; case VLC_CODEC_RGB32: fmt.i_rmask = 0x000000ff; fmt.i_gmask = 0x0000ff00; fmt.i_bmask = 0x00ff0000; break; default: return VLC_EGENERIC; } video_format_FixRgb(&fmt); msg_Dbg(vd, "Pixel format %4.4s", (char*)&fmt.i_chroma); /* Create the associated picture */ picture_resource_t *rsc = &sys->resource; rsc->p_sys = malloc(sizeof(*rsc->p_sys)); if (!rsc->p_sys) goto enomem; rsc->p_sys->sys = sys; for (int i = 0; i < PICTURE_PLANE_MAX; i++) { rsc->p[i].p_pixels = NULL; rsc->p[i].i_pitch = 0; rsc->p[i].i_lines = 0; } picture_t *picture = picture_NewFromResource(&fmt, rsc); if (!picture) goto enomem; /* Wrap it into a picture pool */ picture_pool_configuration_t pool_cfg; memset(&pool_cfg, 0, sizeof(pool_cfg)); pool_cfg.picture_count = 1; pool_cfg.picture = &picture; pool_cfg.lock = AndroidLockSurface; pool_cfg.unlock = AndroidUnlockSurface; sys->pool = picture_pool_NewExtended(&pool_cfg); if (!sys->pool) { picture_Release(picture); goto enomem; } /* Setup vout_display */ vd->sys = sys; vd->fmt = fmt; vd->pool = Pool; vd->display = Display; vd->control = Control; vd->prepare = NULL; vd->manage = NULL; /* Fix initial state */ vout_display_SendEventFullscreen(vd, false); sys->i_sar_num = vd->source.i_sar_num; sys->i_sar_den = vd->source.i_sar_den; return VLC_SUCCESS; enomem: free(rsc->p_sys); free(sys); dlclose(p_library); vlc_mutex_unlock(&single_instance); return VLC_ENOMEM; }
static int OpenCommon(vout_display_t *vd, const vout_display_cfg_t *cfg, video_format_t *fmtp) { vout_display_sys_t *sys; video_format_t fmt, sub_fmt; vout_window_t *embed = cfg->window; if (embed->type != VOUT_WINDOW_TYPE_ANDROID_NATIVE) return VLC_EGENERIC; fmt = *fmtp; if (embed == NULL) return VLC_EGENERIC; assert(embed->handle.anativewindow); AWindowHandler *p_awh = embed->handle.anativewindow; if (!AWindowHandler_canSetVideoLayout(p_awh)) { /* It's better to use gles2 if we are not able to change the video * layout */ return VLC_EGENERIC; } /* Allocate structure */ vd->sys = sys = (struct vout_display_sys_t*)calloc(1, sizeof(*sys)); if (!sys) return VLC_ENOMEM; sys->embed = embed; sys->p_awh = p_awh; sys->anw = AWindowHandler_getANativeWindowAPI(sys->p_awh); sys->i_display_width = cfg->display.width; sys->i_display_height = cfg->display.height; if (fmt.i_chroma != VLC_CODEC_ANDROID_OPAQUE) { /* Setup chroma */ char *psz_fcc = var_InheritString(vd, CFG_PREFIX "chroma"); if (psz_fcc) { fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc); free(psz_fcc); } else fmt.i_chroma = VLC_CODEC_RGB32; switch(fmt.i_chroma) { case VLC_CODEC_YV12: /* avoid swscale usage by asking for I420 instead since the * vout already has code to swap the buffers */ fmt.i_chroma = VLC_CODEC_I420; case VLC_CODEC_I420: break; case VLC_CODEC_RGB16: case VLC_CODEC_RGB32: case VLC_CODEC_RGBA: SetRGBMask(&fmt); video_format_FixRgb(&fmt); break; default: goto error; } } sys->p_window = AndroidWindow_New(vd, &fmt, AWindow_Video); if (!sys->p_window) goto error; if (AndroidWindow_Setup(sys, sys->p_window, 0) != 0) goto error; /* use software rotation if we don't do opaque */ if (!sys->p_window->b_opaque) video_format_TransformTo(&fmt, ORIENT_NORMAL); msg_Dbg(vd, "using %s", sys->p_window->b_opaque ? "opaque" : "ANW"); video_format_ApplyRotation(&sub_fmt, &fmt); sub_fmt.i_chroma = subpicture_chromas[0]; SetRGBMask(&sub_fmt); video_format_FixRgb(&sub_fmt); sys->p_sub_window = AndroidWindow_New(vd, &sub_fmt, AWindow_Subtitles); if (sys->p_sub_window) { FixSubtitleFormat(sys); sys->i_sub_last_order = -1; /* Export the subpicture capability of this vout. */ vd->info.subpicture_chromas = subpicture_chromas; } else if (!vd->obj.force && sys->p_window->b_opaque) { msg_Warn(vd, "cannot blend subtitles with an opaque surface, " "trying next vout"); goto error; } *fmtp = fmt; /* Setup vout_display */ vd->pool = Pool; vd->prepare = Prepare; vd->display = Display; vd->control = Control; vd->info.is_slow = !sys->p_window->b_opaque; return VLC_SUCCESS; error: Close(vd); return VLC_EGENERIC; }
static int EvasImageSetup( vout_display_t *vd ) { vout_display_sys_t *sys = vd->sys; char *psz_fcc = var_InheritString( vd, "evas-image-chroma" ); if( psz_fcc ) { vd->fmt.i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_fcc ); free( psz_fcc ); } switch( vd->fmt.i_chroma ) { case VLC_CODEC_RGB32: sys->u.evas.i_colorspace = EVAS_COLORSPACE_ARGB8888; break; /* Not implemented yet */ #if 0 case VLC_CODEC_RGB16: sys->u.evas.i_colorspace = EVAS_COLORSPACE_RGB565_A5P; break; #endif case VLC_CODEC_YUYV: sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR422601_PL; sys->u.evas.b_yuv = true; break; /* FIXME: SIGSEGV in evas_gl_common_texture_nv12_update */ #if 0 case VLC_CODEC_NV12: sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR420NV12601_PL; sys->u.evas.b_yuv = true; break; #endif case VLC_CODEC_YV12: sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR422P601_PL; sys->u.evas.b_yuv = true; break; default: case VLC_CODEC_I420: sys->u.evas.i_colorspace = EVAS_COLORSPACE_YCBCR422P601_PL; vd->fmt.i_chroma = VLC_CODEC_I420; sys->u.evas.b_yuv = true; break; } evas_object_image_colorspace_set( sys->p_evas, sys->u.evas.i_colorspace ); evas_object_image_data_set( sys->p_evas, NULL ); /* No rotation support with EvasImage */ sys->b_apply_rotation = true; FmtUpdate( vd ); /* No aspect ratio support with EvasImage */ vd->info.has_pictures_invalid = true; sys->pf_set_data = EvasImageSetData; sys->pf_buffers_alloc = EvasImageBuffersAlloc; sys->pf_buffers_free = EvasImageBuffersFree; msg_Dbg( vd, "using evas_image" ); return 0; }