Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Return media changes back
- Loading branch information
Showing
8 changed files
with
224 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* vim:set ts=2 sw=2 sts=2 et cindent: */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "NemoResourceHandler.h" | ||
|
||
#include "nsThreadUtils.h" | ||
#include "mozilla/Services.h" | ||
#include "nsIObserverService.h" | ||
#include "nsStringGlue.h" | ||
#include "mozilla/Preferences.h" | ||
|
||
namespace mozilla { | ||
|
||
NemoResourceHandler* NemoResourceHandler::mGlobalHandler = nullptr; | ||
|
||
void | ||
NemoResourceHandler::AquireResources(void* aHolder) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
nsCOMPtr<nsIObserverService> obs = | ||
mozilla::services::GetObserverService(); | ||
if (obs) { | ||
nsString data; | ||
data.AppendPrintf("{ \"owner\" : \"%p\", \"state\": \"play\" }", aHolder); | ||
obs->NotifyObservers(nullptr, "media-decoder-info", data.get()); | ||
} | ||
|
||
if (Preferences::GetBool("media.resource_handler_disabled", false) == true) { | ||
return; | ||
} | ||
|
||
if (mGlobalHandler == nullptr) | ||
{ | ||
mGlobalHandler = new NemoResourceHandler(); | ||
} | ||
mGlobalHandler->Aquire(); | ||
} | ||
|
||
void | ||
NemoResourceHandler::ReleaseResources(void* aHolder) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
nsCOMPtr<nsIObserverService> obs = | ||
mozilla::services::GetObserverService(); | ||
if (obs) { | ||
nsString data; | ||
data.AppendPrintf("{ \"owner\" : \"%p\", \"state\": \"pause\" }", aHolder); | ||
obs->NotifyObservers(nullptr, "media-decoder-info", data.get()); | ||
} | ||
|
||
if (Preferences::GetBool("media.resource_handler_disabled", false) == true) { | ||
return; | ||
} | ||
|
||
if (!mGlobalHandler) { | ||
return; | ||
} | ||
|
||
mGlobalHandler->Release(); | ||
|
||
if (mGlobalHandler->CanDestroy()) | ||
{ | ||
delete mGlobalHandler; | ||
mGlobalHandler = nullptr; | ||
} | ||
} | ||
|
||
void | ||
NemoResourceHandler::MediaInfo(void* aHolder, bool aHasAudio, bool aHasVideo) | ||
{ | ||
MOZ_ASSERT(NS_IsMainThread()); | ||
nsCOMPtr<nsIObserverService> obs = | ||
mozilla::services::GetObserverService(); | ||
if (obs) { | ||
nsString data; | ||
data.AppendPrintf("{ \"owner\" : \"%p\", \"state\": \"meta\", \"a\" : %i, \"v\" : %i }", aHolder, aHasAudio, aHasVideo); | ||
obs->NotifyObservers(nullptr, "media-decoder-info", data.get()); | ||
} | ||
} | ||
|
||
void | ||
NemoResourceHandler::Aquire() | ||
{ | ||
mCounter++; | ||
} | ||
|
||
void | ||
NemoResourceHandler::Release() | ||
{ | ||
mCounter--; | ||
} | ||
|
||
bool | ||
NemoResourceHandler::CanDestroy() | ||
{ | ||
return mCounter <= 0; | ||
} | ||
|
||
NemoResourceHandler::NemoResourceHandler() | ||
: mCounter(0) | ||
{ | ||
MOZ_ASSERT(mGlobalHandler == nullptr); | ||
mGlobalHandler = this; | ||
} | ||
|
||
NemoResourceHandler::~NemoResourceHandler() | ||
{ | ||
MOZ_ASSERT(mGlobalHandler != nullptr); | ||
mGlobalHandler = nullptr; | ||
} | ||
|
||
} // namespace mozilla | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* vim:set ts=2 sw=2 sts=2 et cindent: */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef NEMO_RESOURCE_HANDLER | ||
#define NEMO_RESOURCE_HANDLER | ||
|
||
namespace mozilla { | ||
|
||
class NemoResourceHandler | ||
{ | ||
public: | ||
static void AquireResources(void* aHolder); | ||
static void ReleaseResources(void* aHolder); | ||
static void MediaInfo(void* aHolder, bool aHasAudio, bool aHasVideo); | ||
private: | ||
NemoResourceHandler(); | ||
virtual ~NemoResourceHandler(); | ||
void Aquire(); | ||
void Release(); | ||
bool CanDestroy(); | ||
|
||
static NemoResourceHandler* mGlobalHandler; | ||
int mCounter; | ||
}; | ||
|
||
} // namespace mozilla | ||
|
||
#endif // NEMO_RESOURCE_HANDLER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters