void VLC::load(const std::string & theFilename) { AC_DEBUG << "VLC::load('" << theFilename << "')"; _EOF = false; _playTime = 0; std::vector<std::string> elements = asl::splitString(theFilename, "#"); if (elements.size() == 2) { _playTime = as<asl::Unsigned64>(elements[1]); AC_DEBUG << "parsed playback position at " << _playTime << " milliseconds."; } _mediaURL = elements[0]; libvlc_media_t *media = libvlc_media_new_location(_libvlc, _mediaURL.c_str()); libvlc_media_player_set_media(_mediaPlayer, media); libvlc_media_release(media); libvlc_video_set_callbacks(_mediaPlayer, VLC::lock, VLC::unlock, VLC::display, this); _rasterEncoding = BGR; setPixelFormat(_rasterEncoding); libvlc_video_set_format_callbacks(_mediaPlayer, VLC::setup_video, VLC::cleanup_video); libvlc_media_player_play(_mediaPlayer); if (_playTime > 0) { libvlc_media_player_set_time(_mediaPlayer, _playTime); } }
void VlcAbstractVideoStream::unsetCallbacks(VlcMediaPlayer *player) { if (player) { libvlc_video_set_callbacks(player->core(), 0, 0, 0, 0); libvlc_video_set_format_callbacks(player->core(), 0, 0); } }
void VlcWindowlessBase::set_player_window() { libvlc_video_set_format_callbacks(getMD(), video_format_proxy, video_cleanup_proxy); libvlc_video_set_callbacks(getMD(), video_lock_proxy, video_unlock_proxy, video_display_proxy, this); }
void VlcAbstractVideoStream::setCallbacks(VlcMediaPlayer *player) { libvlc_video_set_callbacks(player->core(), lockCallbackInternal, unlockCallbackInternal, displayCallbackInternal, this); libvlc_video_set_format_callbacks(player->core(), formatCallbackInternal, formatCleanUpCallbackInternal); }
void VideoMemoryStream::unsetCallbacks(VlcMediaPlayer *player) { libvlc_video_set_callbacks(player->core(), 0, 0, 0, 0); libvlc_video_set_format_callbacks(player->core(), 0, 0); }
int Ibex::VLCVideoPlayer::playVLCVideo(const char *fileName, Display *dpy, GLXDrawable root) { if(mp != 0) { try { pixels = 0; done = true; // Stop stream and clean up libVLC. libvlc_media_player_stop(mp); libvlc_media_player_release(mp); mp = 0; } catch(...) { mp = 0; } } char const *vlc_argv[] = { //"-H" "--text-renderer","none" //"--reset-plugins-cache", //"--reset-config" //"--no-audio", // Don't play audio. //"--no-xlib" // Don't use Xlib. // Apply a video filter. //"--video-filter", "sepia", //"--sepia-intensity=200" }; int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv); int action = 0, pause = 0; context = new struct context(); context->isStereo = isStereo; context->videoTexture = videoTexture; context->player = this; context->dpy = dpy; context->root = root; context->data = data; // create texture/mutex //setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins", 1); // If you don't have this variable set you must have plugins directory // with the executable or libvlc_new() will not work! printf("VLC_PLUGIN_PATH=%s\n", getenv("VLC_PLUGIN_PATH")); // Initialise libVLC. if(libvlc == 0) { libvlc = libvlc_new(vlc_argc, vlc_argv); if(NULL == libvlc) { printf("LibVLC initialization failure.\n"); return EXIT_FAILURE; } } libvlc_media_t *m = libvlc_media_new_path(libvlc, fileName); mp = libvlc_media_player_new_from_media(m); libvlc_media_release(m); m = 0; pixels = new uint32_t[VIDEOWIDTH*VIDEOHEIGHT*4]; memset(pixels, 0, sizeof(uint32_t)*VIDEOWIDTH*VIDEOHEIGHT*4); libvlc_video_set_callbacks(mp, vlclock, vlcunlock, vlcdisplay, context); //libvlc_video_set_format(mp, "RV32", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH*sizeof(uint32_t)); //libvlc_video_set_format(mp, "YUYV", VIDEOWIDTH, VIDEOHEIGHT, VIDEOWIDTH*2); libvlc_video_set_format_callbacks(mp, my_libvlc_video_format_cb, my_libvlc_video_cleanup_cb ); if(libvlc_video_get_size(mp, 0, &width, & height) == 0) { VIDEOWIDTH = width; VIDEOHEIGHT = height; } context->mp = mp; done = false; libvlc_media_player_play(mp); // Main loop. while(!done) { action = 0; switch(action) { case 's': libvlc_media_player_stop(mp); break; case 'q': done = 1; break; case ' ': printf("Pause toggle.\n"); pause = !pause; break; } if(!pause) { context->n++; } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } return 0; }
/** * Thumbnailer main function. * return null if the thumbail generation failed. **/ jbyteArray Java_org_videolan_libvlc_util_VLCUtil_nativeGetThumbnail(JNIEnv *env, jobject thiz, jobject jmedia, const jint frameWidth, const jint frameHeight) { vlcjni_object *p_obj = VLCJniObject_getInstance(env, jmedia); jbyteArray byteArray = NULL; /* Create the thumbnailer data structure */ thumbnailer_sys_t *sys = calloc(1, sizeof(thumbnailer_sys_t)); if (sys == NULL) { LOGE("Could not create the thumbnailer data structure!"); return NULL; } /* Initialize the barrier. */ pthread_mutex_init(&sys->doneMutex, NULL); pthread_cond_init(&sys->doneCondVar, NULL); /* Create a media player playing environment */ libvlc_media_player_t *mp = libvlc_media_player_new_from_media(p_obj->u.p_m); if (!mp) goto end; libvlc_media_player_set_video_title_display(mp, libvlc_position_disable, 0); sys->frameWidth = frameWidth; sys->frameHeight = frameHeight; /* Set the video format and the callbacks. */ libvlc_video_set_callbacks(mp, thumbnailer_lock, thumbnailer_unlock, thumbnailer_display, (void*)sys); libvlc_video_set_format_callbacks(mp, thumbnailer_setup, NULL); libvlc_event_attach(libvlc_media_player_event_manager(mp), libvlc_MediaPlayerPositionChanged, thumbnailer_event, sys); /* Play the media. */ libvlc_media_player_play(mp); libvlc_media_player_set_position(mp, THUMBNAIL_POSITION); /* Wait for the thumbnail to be generated. */ pthread_mutex_lock(&sys->doneMutex); struct timespec deadline; clock_gettime(CLOCK_REALTIME, &deadline); deadline.tv_sec += 3; /* Wait for a VOUT for 3 seconds, some input format like *.TS make some time * to initialize a VOUT */ int ret = 0; while (!(sys->state & THUMB_VOUT) && ret != ETIMEDOUT) ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); if (sys->state & THUMB_VOUT) { ret = 0; /* Wait an additional 7 seconds for a frame */ deadline.tv_sec += 7; while (!(sys->state & THUMB_DONE) && ret != ETIMEDOUT) ret = pthread_cond_timedwait(&sys->doneCondVar, &sys->doneMutex, &deadline); } else LOGE("media has not VOUT"); pthread_mutex_unlock(&sys->doneMutex); /* Stop and release the media player. */ libvlc_media_player_stop(mp); libvlc_event_detach(libvlc_media_player_event_manager(mp), libvlc_MediaPlayerPositionChanged, thumbnailer_event, sys); libvlc_media_player_release(mp); if ((sys->state & THUMB_DONE) && sys->frameData) { /* Create the Java byte array to return the create thumbnail. */ byteArray = (*env)->NewByteArray(env, sys->frameSize); if (byteArray == NULL) { LOGE("Could not allocate the Java byte array to store the frame!"); goto end; } (*env)->SetByteArrayRegion(env, byteArray, 0, sys->frameSize, (jbyte *)sys->frameData); } end: pthread_mutex_destroy(&sys->doneMutex); pthread_cond_destroy(&sys->doneCondVar); free(sys->frameData); free(sys->thumbData); free(sys); return byteArray; }
void VideoSource::UpdateSettings() { EnterCriticalSection(&textureLock); isRendering = false; LeaveCriticalSection(&textureLock); if (mediaPlayer) { libvlc_video_set_callbacks(mediaPlayer, nullptr, nullptr, nullptr, nullptr); libvlc_media_player_stop(mediaPlayer); } config->Reload(); hasSetVolume = false; videoSize.x = float(config->width); videoSize.y = float(config->height); if (mediaPlayer == nullptr) { mediaPlayer = libvlc_media_player_new(vlc); libvlc_event_manager_t *em = libvlc_media_player_event_manager(mediaPlayer); libvlc_event_attach(em, libvlc_MediaPlayerEndReached, vlcEvent, this); libvlc_event_attach(em, libvlc_MediaPlayerPlaying, vlcEvent, this); } if (mediaListPlayer == nullptr) { mediaListPlayer = libvlc_media_list_player_new(vlc); libvlc_media_list_player_set_media_player(mediaListPlayer, mediaPlayer); } else { libvlc_media_list_player_stop(mediaListPlayer); } if (mediaList) { libvlc_media_list_lock(mediaList); while(libvlc_media_list_count(mediaList)) { libvlc_media_list_remove_index(mediaList, 0); } libvlc_media_list_unlock(mediaList); } else { mediaList = libvlc_media_list_new(vlc); libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList); } char *utf8PathOrUrl; for(unsigned int i = 0; i < config->playlist.Num(); i++) { String &mediaEntry = config->playlist[i]; String token = mediaEntry.GetToken(1, L':'); // .. Yup. bool isStream = token.Length() >= 2 && token[0] == L'/' && token[1] == L'/'; utf8PathOrUrl = config->playlist[i].CreateUTF8String(); if (utf8PathOrUrl) { libvlc_media_t *media; if (!isStream) { media = libvlc_media_new_path(vlc, utf8PathOrUrl); } else { media = libvlc_media_new_location(vlc, utf8PathOrUrl); } libvlc_media_list_lock(mediaList); libvlc_media_list_add_media(mediaList, media); libvlc_media_list_unlock(mediaList); libvlc_media_release(media); Free(utf8PathOrUrl); } } if (!config->isPlaylistLooping) { remainingVideos = config->playlist.Num(); } libvlc_video_set_callbacks(mediaPlayer, lock, unlock, display, this); libvlc_video_set_format_callbacks(mediaPlayer, videoFormatProxy, videoCleanupProxy); libvlc_media_list_player_set_playback_mode(mediaListPlayer, config->isPlaylistLooping ? libvlc_playback_mode_loop : libvlc_playback_mode_default); if (!audioOutputStreamHandler) { audioOutputStreamHandler = new AudioOutputStreamHandler(vlc, mediaPlayer); } audioOutputStreamHandler->SetOutputParameters( config->audioOutputType, config->audioOutputTypeDevice, config->audioOutputDevice, config->isAudioOutputToStream); audioOutputStreamHandler->SetVolume(config->volume); // set (possibly in vane) the volume. If it doesn't work it will try later until it works // vlc... que pasa amigo hasSetVolume = libvlc_audio_set_volume(mediaPlayer, config->volume) == 0; EnterCriticalSection(&textureLock); isRendering = true; LeaveCriticalSection(&textureLock); libvlc_media_list_player_play(mediaListPlayer); }
bool CVlcRtspSDK::StartPlay(int screenNum,char *name,HWND inhWnd,char *Rtspurl,int Direction) { StopPlay(); screenNo=screenNum; m_direction=Direction; hWnd=inhWnd; hDC = ::GetDC(hWnd); pDc = CDC::FromHandle(hDC); pDc->SetStretchBltMode(COLORONCOLOR); wchar_t wbuff[1024]; char utf8[1024]; MultiByteToWideChar(CP_ACP, 0, Rtspurl, -1, wbuff, 1024); // buffLen = WideCharToMultiByte(CP_UTF8, 0, wbuff, -1, NULL, 0, 0, 0); // utf8 = new char[buffLen+1]; WideCharToMultiByte(CP_UTF8, 0, wbuff, -1, (LPSTR)utf8, 1024, 0, 0); const char *p=NULL; // 判断rtsp地址是否可以连接 // 使用url去创建一个CYuanRtspClient对象 #if !TEST_DEBUG CYuanRtspClient YuanRtsp(Rtspurl); ERTSPERROR eRet = YuanRtsp.InitSocket(); if (eRet == E_RTSP_SUCCESS) { eRet = YuanRtsp.JudgeCorrect(); if (eRet != E_RTSP_SUCCESS) { DlgMain->ShowCameraMessage(name,"RTSP连接失败 socket不通",FALSE); return false; } } else { DlgMain->ShowCameraMessage(name,"RTSP连接失败 socket不通",FALSE); return false; } #endif #if TEST_DEBUG m_pLibvlc_m = libvlc_media_new_path(m_pLibvlc_Inst,utf8); #else m_pLibvlc_m = libvlc_media_new_location(m_pLibvlc_Inst, utf8); #endif //libvlc_media_new_path m_pLibvlc_Mp = libvlc_media_player_new_from_media(m_pLibvlc_m); libvlc_media_release(m_pLibvlc_m); //libvlc_media_player_set_hwnd(m_pLibvlc_Mp, hWnd); libvlc_video_set_callbacks(m_pLibvlc_Mp, Libvlc_Video_Lock_Callback, Libvlc_Video_UnLock_Callback, Libvlc_Video_Display_Callback, (void *)this); libvlc_video_set_format_callbacks(m_pLibvlc_Mp, Libvlc_Video_Format_Callback, Libvlc_Video_Cleanup_Callback); if(0==libvlc_media_player_play(m_pLibvlc_Mp)) { DlgMain->ShowCameraMessage(name,"连接成功",FALSE); } else { DlgMain->ShowCameraMessage(name,"RTSP连接失败",FALSE); return false; } return true; }