llviewerparcelmedia.cpp 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. /**
  2. * @file llviewerparcelmedia.cpp
  3. * @brief Handlers for multimedia on a per-parcel basis
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llviewerparcelmedia.h"
  34. #include "llcorehttputil.h"
  35. #include "lleventtimer.h"
  36. #include "llmimetypes.h"
  37. #include "llnotifications.h"
  38. #include "llparcel.h"
  39. #include "llpluginclassmedia.h"
  40. #include "llstreamingaudio.h"
  41. #include "llmessage.h"
  42. #include "llagent.h"
  43. #include "llfirstuse.h"
  44. #include "llviewercontrol.h"
  45. #include "llviewermediafocus.h"
  46. #include "llviewerparcelmgr.h"
  47. #include "llviewerregion.h"
  48. #include "llviewertexturelist.h"
  49. ///////////////////////////////////////////////////////////////////////////////
  50. // LLStreamingAudio_MediaPlugins class
  51. ///////////////////////////////////////////////////////////////////////////////
  52. class LLStreamingAudio_MediaPlugins : public LLStreamingAudioInterface
  53. {
  54. protected:
  55. LOG_CLASS(LLStreamingAudio_MediaPlugins);
  56. public:
  57. LLStreamingAudio_MediaPlugins()
  58. : mMediaPlugin(NULL),
  59. mGain(1.f)
  60. {
  61. }
  62. ~LLStreamingAudio_MediaPlugins() override
  63. {
  64. delete mMediaPlugin;
  65. mMediaPlugin = NULL;
  66. }
  67. void start(const std::string& url) override;
  68. void stop() override;
  69. void pause(int pause) override;
  70. void update() override;
  71. S32 isPlaying() override;
  72. void setGain(F32 vol) override;
  73. LL_INLINE F32 getGain() override { return mGain; }
  74. LL_INLINE std::string getURL() override { return mURL; }
  75. private:
  76. LLPluginClassMedia* initializeMedia(const std::string& media_type);
  77. private:
  78. LLPluginClassMedia* mMediaPlugin;
  79. std::string mURL;
  80. F32 mGain;
  81. };
  82. void LLStreamingAudio_MediaPlugins::start(const std::string& url)
  83. {
  84. if (!mMediaPlugin) // lazy-init the underlying media plugin
  85. {
  86. // Assumes that whatever media implementation supports mp3 also
  87. // supports vorbis.
  88. mMediaPlugin = initializeMedia("audio/mpeg");
  89. if (!mMediaPlugin)
  90. {
  91. llwarns << "Cannot start a media plugin for audio/mpeg" << llendl;
  92. return;
  93. }
  94. llinfos << "Media plugin for '" << url << "' is now: "
  95. << mMediaPlugin->getPluginFileName() << llendl;
  96. }
  97. if (url.empty())
  98. {
  99. llinfos << "URL is empty, setting stream to NULL" << llendl;
  100. mURL.clear();
  101. mMediaPlugin->stop();
  102. delete mMediaPlugin;
  103. mMediaPlugin = NULL;
  104. }
  105. else
  106. {
  107. llinfos << "Starting internet stream: " << url << llendl;
  108. mURL = url;
  109. mMediaPlugin->loadURI(url);
  110. mMediaPlugin->start();
  111. }
  112. }
  113. void LLStreamingAudio_MediaPlugins::stop()
  114. {
  115. if (mMediaPlugin)
  116. {
  117. llinfos << "Stopping internet stream: " << mURL << llendl;
  118. mMediaPlugin->stop();
  119. delete mMediaPlugin;
  120. mMediaPlugin = NULL;
  121. }
  122. mURL.clear();
  123. }
  124. void LLStreamingAudio_MediaPlugins::pause(int pause)
  125. {
  126. if (mMediaPlugin)
  127. {
  128. if (pause)
  129. {
  130. mMediaPlugin->pause();
  131. }
  132. else
  133. {
  134. mMediaPlugin->start();
  135. }
  136. }
  137. }
  138. void LLStreamingAudio_MediaPlugins::update()
  139. {
  140. if (mMediaPlugin)
  141. {
  142. mMediaPlugin->idle();
  143. }
  144. }
  145. S32 LLStreamingAudio_MediaPlugins::isPlaying()
  146. {
  147. if (!mMediaPlugin)
  148. {
  149. return 0;
  150. }
  151. // *TODO: can probably do better than this
  152. if (mMediaPlugin->isPluginRunning())
  153. {
  154. return 1; // Active and playing
  155. }
  156. if (mMediaPlugin->isPluginExited())
  157. {
  158. return 0; // stopped
  159. }
  160. return 2; // paused
  161. }
  162. void LLStreamingAudio_MediaPlugins::setGain(F32 vol)
  163. {
  164. vol = llclamp(vol, 0.f, 1.f);
  165. mGain = vol;
  166. if (mMediaPlugin)
  167. {
  168. mMediaPlugin->setVolume(vol);
  169. }
  170. }
  171. LLPluginClassMedia* LLStreamingAudio_MediaPlugins::initializeMedia(const std::string& media_type)
  172. {
  173. LLPluginClassMediaOwner* owner = NULL;
  174. constexpr S32 default_size = 1; // audio-only, be minimal, does not matter
  175. LLPluginClassMedia* media_source;
  176. media_source = LLViewerMediaImpl::newSourceFromMediaType(media_type, owner,
  177. default_size,
  178. default_size);
  179. if (media_source)
  180. {
  181. media_source->setLoop(false); // audio streams are not expected to loop
  182. }
  183. return media_source;
  184. }
  185. ///////////////////////////////////////////////////////////////////////////////
  186. // LLViewerParcelMediaAutoPlay class
  187. ///////////////////////////////////////////////////////////////////////////////
  188. // timer to automatically play media
  189. class LLViewerParcelMediaAutoPlay : LLEventTimer
  190. {
  191. public:
  192. LLViewerParcelMediaAutoPlay()
  193. : LLEventTimer(1),
  194. mPlayed(false),
  195. mTimeInParcel(0)
  196. {
  197. }
  198. bool tick() override;
  199. static void initClass();
  200. static void cleanupClass();
  201. static void playStarted();
  202. private:
  203. S32 mLastParcelID;
  204. bool mPlayed;
  205. F32 mTimeInParcel;
  206. };
  207. constexpr F32 AUTOPLAY_TIME = 5; // How many seconds before we autoplay
  208. // How big the texture must be (pixel area) before we autoplay
  209. constexpr F32 AUTOPLAY_SIZE = 24 * 24;
  210. // How slow should the agent be moving to autoplay
  211. constexpr F32 AUTOPLAY_SPEED = 0.1f;
  212. static LLViewerParcelMediaAutoPlay* sAutoPlay = NULL;
  213. //static
  214. void LLViewerParcelMediaAutoPlay::initClass()
  215. {
  216. if (!sAutoPlay)
  217. {
  218. sAutoPlay = new LLViewerParcelMediaAutoPlay;
  219. }
  220. }
  221. //static
  222. void LLViewerParcelMediaAutoPlay::cleanupClass()
  223. {
  224. if (sAutoPlay)
  225. {
  226. delete sAutoPlay;
  227. sAutoPlay = NULL;
  228. }
  229. }
  230. //static
  231. void LLViewerParcelMediaAutoPlay::playStarted()
  232. {
  233. if (sAutoPlay)
  234. {
  235. sAutoPlay->mPlayed = true;
  236. }
  237. }
  238. bool LLViewerParcelMediaAutoPlay::tick()
  239. {
  240. static LLCachedControl<bool> auto_play(gSavedSettings,
  241. "ParcelMediaAutoPlayEnable");
  242. if (!auto_play)
  243. {
  244. // Don't bother !
  245. mPlayed = false;
  246. return false;
  247. }
  248. LLParcel* this_parcel = gViewerParcelMgr.getAgentParcel();
  249. if (!this_parcel)
  250. {
  251. mPlayed = false;
  252. return false;
  253. }
  254. if (this_parcel->getMediaURL().empty())
  255. {
  256. // No media in this parcel
  257. mPlayed = false;
  258. return false;
  259. }
  260. const LLUUID& this_media_texture_id = this_parcel->getMediaID();
  261. if (this_media_texture_id.isNull())
  262. {
  263. // Bad media texture
  264. mPlayed = false;
  265. return false;
  266. }
  267. if (LLViewerParcelMedia::sMediaImpl.notNull())
  268. {
  269. // Media is already playing !
  270. mPlayed = true;
  271. return false;
  272. }
  273. S32 this_parcel_id = this_parcel->getLocalID();
  274. if (this_parcel_id != mLastParcelID)
  275. {
  276. // we've entered a new parcel
  277. mPlayed = false;
  278. mTimeInParcel = 0;
  279. mLastParcelID = this_parcel_id;
  280. }
  281. // Increase mTimeInParcel by the amount of time between ticks
  282. mTimeInParcel += mPeriod;
  283. if (mTimeInParcel < AUTOPLAY_TIME)
  284. {
  285. // we've not yet been here long enough
  286. mPlayed = false;
  287. return false;
  288. }
  289. if (!mPlayed) // if we've never played
  290. {
  291. F32 image_size = 0;
  292. LLViewerTexture* image;
  293. image = LLViewerTextureManager::getFetchedTexture(this_media_texture_id,
  294. FTT_DEFAULT,
  295. false);
  296. if (image)
  297. {
  298. image_size = image->getMaxVirtualSize();
  299. }
  300. // If the agent is stopped (slow enough)
  301. if (gAgent.getVelocity().length() < AUTOPLAY_SPEED)
  302. {
  303. // and if the target texture is big enough on screen
  304. if (image_size > AUTOPLAY_SIZE)
  305. {
  306. LLViewerParcelMedia::playMedia(this_parcel);
  307. mPlayed = true;
  308. }
  309. }
  310. }
  311. return false; // continue ticking forever please.
  312. }
  313. ///////////////////////////////////////////////////////////////////////////////
  314. // LLViewerParcelMedia class
  315. ///////////////////////////////////////////////////////////////////////////////
  316. // Static Variables
  317. S32 LLViewerParcelMedia::sParcelMusicState = 0;
  318. S32 LLViewerParcelMedia::sMediaParcelLocalID = 0;
  319. LLUUID LLViewerParcelMedia::sMediaRegionID;
  320. viewer_media_t LLViewerParcelMedia::sMediaImpl;
  321. // Local functions
  322. bool callback_play_media(const LLSD& notification, const LLSD& response,
  323. LLParcel* parcel);
  324. //static
  325. void LLViewerParcelMedia::initClass()
  326. {
  327. LLMessageSystem* msg = gMessageSystemp;
  328. msg->setHandlerFunc("ParcelMediaCommandMessage",
  329. processParcelMediaCommandMessage);
  330. msg->setHandlerFunc("ParcelMediaUpdate", processParcelMediaUpdate);
  331. LLViewerParcelMediaAutoPlay::initClass();
  332. }
  333. //static
  334. void LLViewerParcelMedia::cleanupClass()
  335. {
  336. // This needs to be destroyed before global destructor time.
  337. sMediaImpl = NULL;
  338. }
  339. //static
  340. void LLViewerParcelMedia::registerStreamingAudioPlugin()
  341. {
  342. // If the audio engine hasn't set up its own preferred handler for
  343. // streaming audio then set up the generic streaming audio implementation
  344. // which uses media plugins.
  345. if (gAudiop && gAudiop->getStreamingAudioImpl() == NULL)
  346. {
  347. llinfos << "Using media plugins to render streaming audio" << llendl;
  348. gAudiop->setStreamingAudioImpl(new LLStreamingAudio_MediaPlugins());
  349. }
  350. }
  351. //static
  352. void LLViewerParcelMedia::update(LLParcel* parcel)
  353. {
  354. if (parcel)
  355. {
  356. if (!gAgent.getRegion())
  357. {
  358. sMediaRegionID = LLUUID();
  359. stop();
  360. LL_DEBUGS("Media") << "no agent region, bailing out." << LL_ENDL;
  361. return;
  362. }
  363. // we're in a parcel
  364. S32 parcel_id = parcel->getLocalID();
  365. const LLUUID& region_id = gAgent.getRegion()->getRegionID();
  366. if (parcel_id != sMediaParcelLocalID || region_id != sMediaRegionID)
  367. {
  368. LL_DEBUGS("Media") << "New parcel, parcel id = " << parcel_id
  369. << ", region id = " << region_id << LL_ENDL;
  370. sMediaParcelLocalID = parcel_id;
  371. sMediaRegionID = region_id;
  372. }
  373. std::string media_url = parcel->getMediaURL();
  374. const std::string& media_curr_url = parcel->getMediaCurrentURL();
  375. // First use warning
  376. if (!media_url.empty() &&
  377. gSavedSettings.getWarning("FirstStreamingVideo"))
  378. {
  379. gNotifications.add("ParcelCanPlayMedia", LLSD(), LLSD(),
  380. boost::bind(callback_play_media, _1, _2,
  381. parcel));
  382. return;
  383. }
  384. // If we have a current (link sharing) url, use it instead
  385. if (!media_curr_url.empty() &&
  386. parcel->getMediaType() == HTTP_CONTENT_TEXT_HTML)
  387. {
  388. media_url = media_curr_url;
  389. }
  390. LLStringUtil::trim(media_url);
  391. // If no parcel media is playing, nothing left to do
  392. if (sMediaImpl.isNull())
  393. {
  394. playMedia(parcel);
  395. return;
  396. }
  397. // Media is playing... has something changed ?
  398. else if (sMediaImpl->getMediaURL() != media_url ||
  399. sMediaImpl->getMediaTextureID() != parcel->getMediaID() ||
  400. sMediaImpl->getMimeType() != parcel->getMediaType())
  401. {
  402. // Only play if the media types are the same.
  403. if (sMediaImpl->getMimeType() == parcel->getMediaType())
  404. {
  405. playMedia(parcel);
  406. }
  407. else
  408. {
  409. stop();
  410. }
  411. }
  412. }
  413. else
  414. {
  415. stop();
  416. }
  417. }
  418. //static
  419. void LLViewerParcelMedia::playMedia(LLParcel* parcel, bool filter)
  420. {
  421. if (!parcel || parcel != gViewerParcelMgr.getAgentParcel() ||
  422. !gSavedSettings.getBool("EnableStreamingMedia"))
  423. {
  424. return;
  425. }
  426. std::string media_url = parcel->getMediaURL();
  427. LLStringUtil::trim(media_url);
  428. if (!media_url.empty() && gSavedSettings.getBool("MediaEnableFilter") &&
  429. (filter || !LLViewerMedia::allowedMedia(media_url)))
  430. {
  431. // If filtering is needed or in case media_url just changed
  432. // to something we did not yet approve.
  433. LLViewerParcelMediaAutoPlay::playStarted();
  434. LLViewerMedia::filterParcelMedia(parcel, 0);
  435. return;
  436. }
  437. std::string mime_type = parcel->getMediaType();
  438. const LLUUID& placeholder_texture_id = parcel->getMediaID();
  439. bool media_auto_scale = parcel->getMediaAutoScale();
  440. bool media_loop = parcel->getMediaLoop();
  441. S32 media_width = parcel->getMediaWidth();
  442. S32 media_height = parcel->getMediaHeight();
  443. // Debug print
  444. LL_DEBUGS("Media") << "Play media type: " << mime_type << ", url : "
  445. << media_url << LL_ENDL;
  446. if (sMediaImpl)
  447. {
  448. // If the url and mime type are the same, call play again
  449. if (sMediaImpl->getMediaURL() == media_url &&
  450. sMediaImpl->getMimeType() == mime_type &&
  451. sMediaImpl->getMediaTextureID() == placeholder_texture_id)
  452. {
  453. LL_DEBUGS("Media") << "playing with existing url " << media_url
  454. << LL_ENDL;
  455. sMediaImpl->play();
  456. }
  457. else
  458. {
  459. // Since the texture id is different, we need to generate a new
  460. // impl. Delete the old media impl first so they don't fight over
  461. // the texture. A new impl will be created below.
  462. sMediaImpl->stop();
  463. sMediaImpl = NULL;
  464. }
  465. }
  466. // Don't ever try to play if the media type is set to "none/none"
  467. if (stricmp(mime_type.c_str(),
  468. LLMIMETypes::getDefaultMimeType().c_str()) != 0)
  469. {
  470. if (!sMediaImpl)
  471. {
  472. LL_DEBUGS("Media") << "new media impl with mime type " << mime_type
  473. << ", url " << media_url << LL_ENDL;
  474. // There is no media impl, make a new one
  475. sMediaImpl = LLViewerMedia::newMediaImpl(placeholder_texture_id,
  476. media_width, media_height,
  477. media_auto_scale,
  478. media_loop);
  479. sMediaImpl->setIsParcelMedia(true);
  480. sMediaImpl->navigateTo(media_url, mime_type, true);
  481. }
  482. LLFirstUse::useMedia();
  483. LLViewerParcelMediaAutoPlay::playStarted();
  484. }
  485. }
  486. //static
  487. void LLViewerParcelMedia::play(void* userdata)
  488. {
  489. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  490. if (parcel)
  491. {
  492. LLViewerMedia::sIsUserAction = true;
  493. playMedia(parcel);
  494. }
  495. }
  496. //static
  497. void LLViewerParcelMedia::stop(void* userdata)
  498. {
  499. if (sMediaImpl.notNull())
  500. {
  501. // We need to remove the media HUD if it is up.
  502. LLViewerMediaFocus::getInstance()->clearFocus();
  503. // This will kill the media instance.
  504. sMediaImpl->stop();
  505. sMediaImpl = NULL;
  506. }
  507. }
  508. //static
  509. void LLViewerParcelMedia::pause(void* userdata)
  510. {
  511. if (sMediaImpl.notNull())
  512. {
  513. sMediaImpl->pause();
  514. }
  515. }
  516. //static
  517. void LLViewerParcelMedia::start()
  518. {
  519. if (sMediaImpl.notNull())
  520. {
  521. sMediaImpl->start();
  522. LLFirstUse::useMedia();
  523. LLViewerParcelMediaAutoPlay::playStarted();
  524. }
  525. }
  526. //static
  527. void LLViewerParcelMedia::seek(F32 time)
  528. {
  529. if (sMediaImpl.notNull())
  530. {
  531. sMediaImpl->seek(time);
  532. }
  533. }
  534. //static
  535. void LLViewerParcelMedia::focus(bool focus)
  536. {
  537. if (sMediaImpl.notNull())
  538. {
  539. sMediaImpl->focus(focus);
  540. }
  541. }
  542. //static
  543. LLViewerMediaImpl::EMediaStatus LLViewerParcelMedia::getStatus()
  544. {
  545. if (sMediaImpl.notNull() && sMediaImpl->hasMedia())
  546. {
  547. return sMediaImpl->getMediaPlugin()->getStatus();
  548. }
  549. return LLViewerMediaImpl::MEDIA_NONE;
  550. }
  551. //static
  552. std::string LLViewerParcelMedia::getMimeType()
  553. {
  554. return sMediaImpl.notNull() ? sMediaImpl->getMimeType()
  555. : LLMIMETypes::getDefaultMimeType();
  556. }
  557. //static
  558. std::string LLViewerParcelMedia::getURL()
  559. {
  560. std::string url;
  561. if (sMediaImpl.notNull())
  562. {
  563. url = sMediaImpl->getMediaURL();
  564. }
  565. LLStringUtil::trim(url);
  566. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  567. if (parcel && stricmp(parcel->getMediaType().c_str(),
  568. LLMIMETypes::getDefaultMimeType().c_str()) != 0)
  569. {
  570. if (url.empty())
  571. {
  572. url = parcel->getMediaCurrentURL();
  573. }
  574. if (url.empty())
  575. {
  576. url = parcel->getMediaURL();
  577. }
  578. }
  579. return url;
  580. }
  581. //static
  582. std::string LLViewerParcelMedia::getParcelAudioURL()
  583. {
  584. std::string music_url;
  585. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  586. if (parcel)
  587. {
  588. music_url = parcel->getMusicURL();
  589. LLStringUtil::trim(music_url);
  590. }
  591. return music_url;
  592. }
  593. //static
  594. std::string LLViewerParcelMedia::getName()
  595. {
  596. return sMediaImpl.notNull() ? sMediaImpl->getName() : "";
  597. }
  598. //static
  599. void LLViewerParcelMedia::processParcelMediaCommandMessage(LLMessageSystem* msg,
  600. void**)
  601. {
  602. // extract the agent id
  603. //LLUUID agent_id;
  604. //msg->getUUID(agent_id);
  605. U32 flags;
  606. U32 command;
  607. F32 time;
  608. msg->getU32("CommandBlock", "Flags", flags);
  609. msg->getU32("CommandBlock", "Command", command);
  610. msg->getF32("CommandBlock", "Time", time);
  611. if (flags & ((1 << PARCEL_MEDIA_COMMAND_STOP) |
  612. (1 << PARCEL_MEDIA_COMMAND_PAUSE) |
  613. (1 << PARCEL_MEDIA_COMMAND_PLAY) |
  614. (1 << PARCEL_MEDIA_COMMAND_LOOP) |
  615. (1 << PARCEL_MEDIA_COMMAND_UNLOAD)))
  616. {
  617. if (command == PARCEL_MEDIA_COMMAND_STOP)
  618. {
  619. stop();
  620. }
  621. else if (command == PARCEL_MEDIA_COMMAND_PAUSE)
  622. {
  623. pause();
  624. }
  625. else if (command == PARCEL_MEDIA_COMMAND_PLAY ||
  626. command == PARCEL_MEDIA_COMMAND_LOOP)
  627. {
  628. if (getStatus() == LLViewerMediaImpl::MEDIA_PAUSED)
  629. {
  630. start();
  631. }
  632. else
  633. {
  634. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  635. playMedia(parcel);
  636. }
  637. }
  638. else if (command == PARCEL_MEDIA_COMMAND_UNLOAD)
  639. {
  640. stop();
  641. }
  642. }
  643. if (flags & (1 << PARCEL_MEDIA_COMMAND_TIME))
  644. {
  645. if (sMediaImpl.isNull())
  646. {
  647. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  648. playMedia(parcel);
  649. }
  650. seek(time);
  651. }
  652. }
  653. //static
  654. void LLViewerParcelMedia::processParcelMediaUpdate(LLMessageSystem* msg,
  655. void**)
  656. {
  657. LLUUID media_id;
  658. std::string media_url;
  659. std::string media_type;
  660. S32 media_width = 0;
  661. S32 media_height = 0;
  662. U8 temp;
  663. bool media_auto_scale = false;
  664. bool media_loop = false;
  665. msg->getUUID("DataBlock", "MediaID", media_id);
  666. char media_url_buffer[257];
  667. msg->getString("DataBlock", "MediaURL", 255, media_url_buffer);
  668. media_url = media_url_buffer;
  669. msg->getU8("DataBlock", "MediaAutoScale", temp);
  670. media_auto_scale = (bool)temp;
  671. if (msg->has("DataBlockExtended")) // do we have the extended data?
  672. {
  673. char media_type_buffer[257];
  674. msg->getString("DataBlockExtended", "MediaType", 255,
  675. media_type_buffer);
  676. media_type = media_type_buffer;
  677. msg->getU8("DataBlockExtended", "MediaLoop", temp);
  678. media_loop = (bool)temp;
  679. msg->getS32("DataBlockExtended", "MediaWidth", media_width);
  680. msg->getS32("DataBlockExtended", "MediaHeight", media_height);
  681. }
  682. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  683. if (parcel)
  684. {
  685. if (parcel->getMediaURL() != media_url ||
  686. parcel->getMediaType() != media_type ||
  687. parcel->getMediaID() != media_id ||
  688. parcel->getMediaWidth() != media_width ||
  689. parcel->getMediaHeight() != media_height ||
  690. parcel->getMediaAutoScale() != media_auto_scale ||
  691. parcel->getMediaLoop() != media_loop)
  692. {
  693. // temporarily store these new values in the parcel
  694. parcel->setMediaURL(media_url);
  695. parcel->setMediaType(media_type);
  696. parcel->setMediaID(media_id);
  697. parcel->setMediaWidth(media_width);
  698. parcel->setMediaHeight(media_height);
  699. parcel->setMediaAutoScale(media_auto_scale);
  700. parcel->setMediaLoop(media_loop);
  701. playMedia(parcel);
  702. }
  703. }
  704. }
  705. //static
  706. void LLViewerParcelMedia::sendMediaNavigateMessage(const std::string& url)
  707. {
  708. const std::string& cap_url =
  709. gAgent.getRegionCapability("ParcelNavigateMedia");
  710. if (cap_url.empty())
  711. {
  712. llwarns << "Cannot get ParcelNavigateMedia capability" << llendl;
  713. return;
  714. }
  715. // Send a navigate event to sim for link sharing
  716. LLSD body;
  717. body["agent-id"] = gAgentID;
  718. body["local-id"] = gViewerParcelMgr.getAgentParcel()->getLocalID();
  719. body["url"] = url;
  720. LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(cap_url, body,
  721. "Media navigation sent to sim.",
  722. "Failed to send media navigation to sim.");
  723. }
  724. // inherited from LLViewerMediaObserver
  725. //virtual
  726. void LLViewerParcelMedia::handleMediaEvent(LLPluginClassMedia* self,
  727. EMediaEvent event)
  728. {
  729. if (!self) return;
  730. switch (event)
  731. {
  732. case MEDIA_EVENT_DEBUG_MESSAGE:
  733. #if 0
  734. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_DEBUG_MESSAGE"
  735. << LL_ENDL;
  736. #endif
  737. break;
  738. case MEDIA_EVENT_CONTENT_UPDATED:
  739. #if 0
  740. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_CONTENT_UPDATED"
  741. << LL_ENDL;
  742. #endif
  743. break;
  744. case MEDIA_EVENT_TIME_DURATION_UPDATED:
  745. #if 0
  746. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_TIME_DURATION_UPDATED, time is "
  747. << self->getCurrentTime() << " of "
  748. << self->getDuration() << LL_ENDL;
  749. #endif
  750. break;
  751. case MEDIA_EVENT_SIZE_CHANGED:
  752. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_SIZE_CHANGED"
  753. << LL_ENDL;
  754. break;
  755. case MEDIA_EVENT_CURSOR_CHANGED:
  756. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_CURSOR_CHANGED, new cursor is "
  757. << self->getCursorName() << LL_ENDL;
  758. break;
  759. case MEDIA_EVENT_NAVIGATE_BEGIN:
  760. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_NAVIGATE_BEGIN"
  761. << LL_ENDL;
  762. break;
  763. case MEDIA_EVENT_NAVIGATE_COMPLETE:
  764. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_NAVIGATE_COMPLETE, result string is: "
  765. << self->getNavigateResultString() << LL_ENDL;
  766. break;
  767. case MEDIA_EVENT_PROGRESS_UPDATED:
  768. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_PROGRESS_UPDATED, loading at "
  769. << self->getProgressPercent() << "%" << LL_ENDL;
  770. break;
  771. case MEDIA_EVENT_STATUS_TEXT_CHANGED:
  772. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_STATUS_TEXT_CHANGED, new status text is: "
  773. << self->getStatusText() << LL_ENDL;
  774. break;
  775. case MEDIA_EVENT_LOCATION_CHANGED:
  776. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_LOCATION_CHANGED, new uri is: "
  777. << self->getLocation() << LL_ENDL;
  778. break;
  779. case MEDIA_EVENT_NAVIGATE_ERROR_PAGE:
  780. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_NAVIGATE_ERROR_PAGE"
  781. << LL_ENDL;
  782. break;
  783. case MEDIA_EVENT_CLICK_LINK_HREF:
  784. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_CLICK_LINK_HREF, target is \""
  785. << self->getClickTarget() << "\", uri is "
  786. << self->getClickURL() << LL_ENDL;
  787. break;
  788. case MEDIA_EVENT_CLICK_LINK_NOFOLLOW:
  789. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_CLICK_LINK_NOFOLLOW, uri is "
  790. << self->getClickURL() << LL_ENDL;
  791. break;
  792. case MEDIA_EVENT_PLUGIN_FAILED:
  793. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_PLUGIN_FAILED"
  794. << LL_ENDL;
  795. break;
  796. case MEDIA_EVENT_PLUGIN_FAILED_LAUNCH:
  797. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_PLUGIN_FAILED_LAUNCH"
  798. << LL_ENDL;
  799. break;
  800. case MEDIA_EVENT_NAME_CHANGED:
  801. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_NAME_CHANGED"
  802. << LL_ENDL;
  803. break;
  804. case MEDIA_EVENT_CLOSE_REQUEST:
  805. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_CLOSE_REQUEST"
  806. << LL_ENDL;
  807. break;
  808. case MEDIA_EVENT_PICK_FILE_REQUEST:
  809. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_PICK_FILE_REQUEST"
  810. << LL_ENDL;
  811. break;
  812. case MEDIA_EVENT_FILE_DOWNLOAD:
  813. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_FILE_DOWNLOAD"
  814. << LL_ENDL;
  815. break;
  816. case MEDIA_EVENT_GEOMETRY_CHANGE:
  817. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_GEOMETRY_CHANGE, uuid is "
  818. << self->getClickUUID() << LL_ENDL;
  819. break;
  820. case MEDIA_EVENT_AUTH_REQUEST:
  821. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_AUTH_REQUEST, url "
  822. << self->getAuthURL() << ", realm "
  823. << self->getAuthRealm() << LL_ENDL;
  824. break;
  825. case MEDIA_EVENT_LINK_HOVERED:
  826. LL_DEBUGS("Media") << "Media event: MEDIA_EVENT_LINK_HOVERED, hover text is: "
  827. << self->getHoverText() << LL_ENDL;
  828. }
  829. }
  830. bool callback_play_media(const LLSD& notification, const LLSD& response,
  831. LLParcel* parcel)
  832. {
  833. S32 option = LLNotification::getSelectedOption(notification, response);
  834. if (option == 0)
  835. {
  836. gSavedSettings.setBool("EnableStreamingMedia", true);
  837. LLViewerParcelMedia::playMedia(parcel);
  838. }
  839. else
  840. {
  841. gSavedSettings.setBool("EnableStreamingMedia", false);
  842. }
  843. gSavedSettings.setWarning("FirstStreamingVideo", false);
  844. return false;
  845. }
  846. #if 0 // TODO: observer
  847. void LLViewerParcelMediaNavigationObserver::onNavigateComplete(const EventType& event_in)
  848. {
  849. std::string url = event_in.getStringValue();
  850. if (mCurrentURL != url && !mFromMessage)
  851. {
  852. LLViewerParcelMedia::sendMediaNavigateMessage(url);
  853. }
  854. mCurrentURL = url;
  855. mFromMessage = false;
  856. }
  857. #endif
  858. //static
  859. void LLViewerParcelMedia::playStreamingMusic(LLParcel* parcel, bool filter)
  860. {
  861. if (!parcel || parcel != gViewerParcelMgr.getAgentParcel() ||
  862. !gSavedSettings.getBool("EnableStreamingMusic"))
  863. {
  864. return;
  865. }
  866. std::string music_url = parcel->getMusicURL();
  867. LLStringUtil::trim(music_url);
  868. if (!music_url.empty() && gSavedSettings.getBool("MediaEnableFilter") &&
  869. (filter || !LLViewerMedia::allowedMedia(music_url)))
  870. {
  871. // If filtering is needed or in case music_url just changed
  872. // to something we did not yet approve.
  873. LLViewerMedia::filterParcelMedia(parcel, 1);
  874. }
  875. else if (gAudiop)
  876. {
  877. LLStreamingAudioInterface* stream = gAudiop->getStreamingAudioImpl();
  878. if (stream && stream->supportsAdjustableBufferSizes())
  879. {
  880. stream->setBufferSizes(gSavedSettings.getU32("FMODStreamBufferSize"),
  881. gSavedSettings.getU32("FMODDecodeBufferSize"));
  882. }
  883. gAudiop->startInternetStream(music_url);
  884. if (music_url.empty())
  885. {
  886. sParcelMusicState = STOPPED;
  887. }
  888. else
  889. {
  890. sParcelMusicState = PLAYING;
  891. }
  892. }
  893. }
  894. //static
  895. void LLViewerParcelMedia::stopStreamingMusic()
  896. {
  897. if (gAudiop)
  898. {
  899. gAudiop->stopInternetStream();
  900. sParcelMusicState = STOPPED;
  901. }
  902. }
  903. //static
  904. void LLViewerParcelMedia::playMusic(void*)
  905. {
  906. if (gAudiop)
  907. {
  908. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  909. if (parcel)
  910. {
  911. // this doesn't work properly when crossing parcel boundaries
  912. // - even when the stream is stopped, it doesn't return the right
  913. // thing - commenting out for now.
  914. //if (gAudiop->isInternetStreamPlaying() == 0)
  915. {
  916. LLViewerMedia::sIsUserAction = true;
  917. playStreamingMusic(parcel);
  918. }
  919. }
  920. }
  921. }
  922. //static
  923. void LLViewerParcelMedia::pauseMusic(void*)
  924. {
  925. if (gAudiop)
  926. {
  927. gAudiop->pauseInternetStream(1);
  928. sParcelMusicState = PAUSED;
  929. }
  930. }
  931. //static
  932. void LLViewerParcelMedia::stopMusic(void*)
  933. {
  934. stopStreamingMusic();
  935. }