Closed Bug 1112219 Opened 10 years ago Closed 9 years ago

Implement platform independent MediaResourceManager

Categories

(Core :: Audio/Video, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla42
Tracking Status
firefox42 --- fixed

People

(Reporter: sotaro, Assigned: sotaro)

References

Details

Attachments

(6 files, 32 obsolete files)

48.98 KB, patch
cpearce
: review+
Details | Diff | Splinter Review
100.09 KB, application/pdf
Details
12.41 KB, patch
nical
: review+
Details | Diff | Splinter Review
8.18 KB, patch
sotaro
: review+
Details | Diff | Splinter Review
13.99 KB, patch
sotaro
: review+
Details | Diff | Splinter Review
43.05 KB, patch
sotaro
: review+
Details | Diff | Splinter Review
MediaResourceManager is implement as gonk specific. It is necessary by platform independent implementation. http://mxr.mozilla.org/mozilla-central/source/dom/media/omx/mediaresourcemanager/
gecko IPC communication need to be handled as Off-Main-Thread way. It seems nice to implement it by using PBackground.
Assignee: nobody → sotaro.ikeda.g
wip patch under implementing.
Attached file class diagram of MediaResourceManager (obsolete) —
Attached file class diagram of MediaResourceManager (obsolete) —
Attachment #8585488 - Attachment is obsolete: true
Attachment #8585490 - Attachment is patch: false
Attached file class diagram of MediaResourceManager (obsolete) —
Attachment #8585490 - Attachment is obsolete: true
un-bitrot.
Attachment #8585479 - Attachment is obsolete: true
If we want MediaResourceManager to be efficient, its IPC thread need to be non-main thread. Then at first, I thought that PBackground could handle this. But it has one big problem. PBackground and its actor could not be created synchronously. MediaResourceManager need to handle synchronous wait use case. If ipc actor is not created when the wait is requested, it can not handle the request. If we want to avoid this case, we need to create the ipc actor as soon as possible when the process is loaded. It means add one more thread to the process.
(In reply to Sotaro Ikeda [:sotaro] from comment #8) > possible when the process is loaded. It means add one more thread to the > process. We already have similar thread. It is ImageBridge thread. Until PBackground's creation problem is addressed, it seems better to use ImageBridge thread. On b2g gonk, gecko supports only ImageBridge enabled environment.
Attached patch patch - Add MediaResourceManager (obsolete) — Splinter Review
Attachment #8602290 - Attachment is obsolete: true
Attached patch patch - Add MediaResourceManager (obsolete) — Splinter Review
Rebased
Attachment #8609614 - Attachment is obsolete: true
Attached patch patch - Add MediaResourceManager (obsolete) — Splinter Review
Fix nits.
Attachment #8612993 - Attachment is obsolete: true
Attachment #8613059 - Attachment is obsolete: true
Attachment #8613075 - Attachment description: patch - Remove gonk specific MediaResourceManagerService → patch part 5 - Remove gonk specific MediaResourceManagerService
Fix assert checks.
Attachment #8613092 - Attachment is obsolete: true
Fix constructor.
Attachment #8613506 - Attachment is obsolete: true
Fix shutdown.
Attachment #8613553 - Attachment is obsolete: true
Fix shutdown.
Attachment #8613095 - Attachment is obsolete: true
Add error handling
Attachment #8613666 - Attachment is obsolete: true
Remove ClearOnShutdown from MediaResourceService.
Attachment #8614176 - Attachment is obsolete: true
correct patch.
Attachment #8614731 - Attachment is obsolete: true
Remove unnecessary assert.
Attachment #8614735 - Attachment is obsolete: true
Fix around shutdown handling.
Attachment #8615000 - Attachment is obsolete: true
Fix build failure.
Attachment #8615392 - Attachment is obsolete: true
Update a function name.
Attachment #8615418 - Attachment is obsolete: true
Update a function name.
Attachment #8613098 - Attachment is obsolete: true
Update a diagram based on latest implementation. At first, I planed to use PBackground, but it could not be used for MediaResourceManager, because it request to use main thread for actor creation. For the time being, I chose ImageBridge thread for MediaResourceManager.
Attachment #8615978 - Flags: review?(cpearce)
Comment on attachment 8615978 [details] [diff] [review] patch part 1 - Add MediaResourceManager Review of attachment 8615978 [details] [diff] [review]: ----------------------------------------------------------------- You should also get an IPC peer to look at this. Maybe nical? Can you use MediaPromises here for async operations? We should use them for all async operations in new code if possible. See also: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Guide/Hashtables ::: dom/media/systemservices/MediaResourceClient.h @@ +49,5 @@ > + bool SetListener(MediaResourceReservationListener* aListener); > + > + // Try to acquire media resource asynchronously. > + // If the resource is used by others, wait until acquired. > + void Acquire(); An Acquire() call results in only one callback to the MediaResourceReservationListener, right? Can this return a MediaPromise instead, and resolve/reject the promise when complete, rather than calling the callback? MediaPromises are how we should do async operations in new code. ::: dom/media/systemservices/MediaResourceManager.cpp @@ +94,5 @@ > + ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( > + FROM_HERE, > + NewRunnableFunction(&MediaResourceManager_InitSync, &barrier, &done)); > + // should stop the thread until done. > + while (!done) { Can this deadlock? What if the imagebridge messageloop thread is blocked waiting on this thread (which thread is that? the main thread?). This seems like it could be a source of deadlocks to me. Can Init() return a MediaPromise and become properly async? It's hard to tell as the rest of the patch is not present? @@ +265,5 @@ > + &MediaResourceManager::DoAcquire, > + aClient->mId)); > + > + // should stop the thread until done. > + while (!done) { Same comment here; can this deadlock? ::: dom/media/systemservices/MediaResourceManager.h @@ +71,5 @@ > + bool mShutDown; > + > + media::MediaResourceManagerChild* mChild; > + > + std::map<int32_t, MediaResourceClient*> mResourceClients; You should use nsRefPtrHashtable<nsUint32HashKey, MediaResourceClient> here, as that will addref/release the MediaResourceClients you put in. ::: dom/media/systemservices/MediaResourceManagerParent.h @@ +42,5 @@ > + bool mDestroyed; > + > + nsRefPtr<MediaResourceService> mMediaResourceService; > + > + std::map<int32_t, MediaResourceRequest> mResourceRequests; nsClassHashtable ::: dom/media/systemservices/PMediaResourceManager.ipdl @@ +11,5 @@ > +namespace mozilla { > +namespace media { > + > +/* > + * The PMediaResourceManager is a sub-protocol in PImageBridge Can we rename "*MediaResource*" to "*CodecResource*", so that it's clear that this is different from a MediaResource, i.e. the thing that we read data from?
Comment on attachment 8615978 [details] [diff] [review] patch part 1 - Add MediaResourceManager Review of attachment 8615978 [details] [diff] [review]: ----------------------------------------------------------------- Will drop review request for now; if you can use MediaPromieses here, please rework your patch to. If not, re-request review, assuming you can't remove the sync dispatches.
Attachment #8615978 - Flags: review?(cpearce)
(In reply to Chris Pearce (:cpearce) from comment #40) > ----------------------------------------------------------------- > > Will drop review request for now; if you can use MediaPromieses here, please > rework your patch to. If not, re-request review, assuming you can't remove > the sync dispatches. We can't remove sync operation API. It is required by WebRTC code. And IIRC, MediaPromieses is expected to be used only on main thread and MediaTaskQueue thread.
(In reply to Chris Pearce (:cpearce) from comment #39) > Comment on attachment 8615978 [details] [diff] [review] > patch part 1 - Add MediaResourceManager > > Review of attachment 8615978 [details] [diff] [review]: > ----------------------------------------------------------------- > > You should also get an IPC peer to look at this. Maybe nical? > > Can you use MediaPromises here for async operations? We should use them for > all async operations in new code if possible. I do not think it is a good idea to use MediaPromises here at this time. If we use MediaPromise for async operation, caller side is also necessary to be prepared to handle it. We could not assume it for all future use cases. In future, Firefox OS TV might use this capability. But we do not know which code uses this capability in which purpose. If callback is used, it is easy to connect to MediaPromise. It is already done in this bug in MediaOMXReader and MediaCodecReader cases. > > See also: > https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Guide/Hashtables > > ::: dom/media/systemservices/MediaResourceClient.h > @@ +49,5 @@ > > + bool SetListener(MediaResourceReservationListener* aListener); > > + > > + // Try to acquire media resource asynchronously. > > + // If the resource is used by others, wait until acquired. > > + void Acquire(); > > An Acquire() call results in only one callback to the > MediaResourceReservationListener, right? Yes. > Can this return a MediaPromise > instead, and resolve/reject the promise when complete, rather than calling > the callback? MediaPromises are how we should do async operations in new > code. In this bug, I want to keep current callback implementation for the time being as explained in the above. > > ::: dom/media/systemservices/MediaResourceManager.cpp > @@ +94,5 @@ > > + ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( > > + FROM_HERE, > > + NewRunnableFunction(&MediaResourceManager_InitSync, &barrier, &done)); > > + // should stop the thread until done. > > + while (!done) { > > Can this deadlock? What if the imagebridge messageloop thread is blocked > waiting on this thread (which thread is that? the main thread?). This seems > like it could be a source of deadlocks to me. ImageBridge thread is not blocked by other threads except IPC operation. Therefore deadlock by main thread or other thread in process should not happen. > > Can Init() return a MediaPromise and become properly async? It's hard to > tell as the rest of the patch is not present? We need to support MediaResourceClient::AcquireSyncNoWait(). It is sync operation. To support it, we can not make Init() as to return a MediaPromise. > > @@ +265,5 @@ > > + &MediaResourceManager::DoAcquire, > > + aClient->mId)); > > + > > + // should stop the thread until done. > > + while (!done) { > > Same comment here; can this deadlock? I do not think there is a risk of deadlock as explained above except ImageBridge shutdown. > > ::: dom/media/systemservices/MediaResourceManager.h > @@ +71,5 @@ > > + bool mShutDown; > > + > > + media::MediaResourceManagerChild* mChild; > > + > > + std::map<int32_t, MediaResourceClient*> mResourceClients; > > You should use nsRefPtrHashtable<nsUint32HashKey, MediaResourceClient> > here, as that will addref/release the MediaResourceClients you put in. I'll update it. > > ::: dom/media/systemservices/MediaResourceManagerParent.h > @@ +42,5 @@ > > + bool mDestroyed; > > + > > + nsRefPtr<MediaResourceService> mMediaResourceService; > > + > > + std::map<int32_t, MediaResourceRequest> mResourceRequests; > > nsClassHashtable I'll update it. > > ::: dom/media/systemservices/PMediaResourceManager.ipdl > @@ +11,5 @@ > > +namespace mozilla { > > +namespace media { > > + > > +/* > > + * The PMediaResourceManager is a sub-protocol in PImageBridge > > Can we rename "*MediaResource*" to "*CodecResource*", so that it's clear > that this is different from a MediaResource, i.e. the thing that we read > data from? For example, Firefox OS TV might use this capability in ture, in this case, we could not expect the resource is only CodecResource. Is there another better name?
Flags: needinfo?(cpearce)
> > > > Can Init() return a MediaPromise and become properly async? It's hard to > > tell as the rest of the patch is not present? > > We need to support MediaResourceClient::AcquireSyncNoWait(). It is sync > operation. To support it, we can not make Init() as to return a MediaPromise. > AcquireSyncNoWait() support and on demand MediaResourceManager creation make Init() to sync.
(In reply to Sotaro Ikeda [:sotaro] from comment #42) > (In reply to Chris Pearce (:cpearce) from comment #39) > > Comment on attachment 8615978 [details] [diff] [review] > > patch part 1 - Add MediaResourceManager > > > > Review of attachment 8615978 [details] [diff] [review]: > > ----------------------------------------------------------------- > > > > You should also get an IPC peer to look at this. Maybe nical? > > > > Can you use MediaPromises here for async operations? We should use them for > > all async operations in new code if possible. > > I do not think it is a good idea to use MediaPromises here at this time. If > we use MediaPromise for async operation, caller side is also necessary to be > prepared to handle it. We could not assume it for all future use cases. In > future, Firefox OS TV might use this capability. But we do not know which > code uses this capability in which purpose. Actually, WebRTC code does not fit to MediaPromises and use sync operation to reserve the resources.
Attachment #8585492 - Attachment is obsolete: true
> > > > Can you use MediaPromises here for async operations? We should use them for > > all async operations in new code if possible. > > I do not think it is a good idea to use MediaPromises here at this time. If > we use MediaPromise for async operation, caller side is also necessary to be > prepared to handle it. We could not assume it for all future use cases. In > future, Firefox OS TV might use this capability. But we do not know which > code uses this capability in which purpose. > > If callback is used, it is easy to connect to MediaPromise. It is already > done in this bug in MediaOMXReader and MediaCodecReader cases. Sorry, it is not done in this bug. It is already done by Bug 1168456 and Bug 1167608.
(In reply to Sotaro Ikeda [:sotaro] from comment #42) > ImageBridge thread is not blocked by other threads except IPC operation. > Therefore deadlock by main thread or other thread in process should not > happen. > ImageBridge is designed as not to be blocked by other threads like main thread. If it happens, it is a defect.
(In reply to Sotaro Ikeda [:sotaro] from comment #42) > (In reply to Chris Pearce (:cpearce) from comment #39) > > Comment on attachment 8615978 [details] [diff] [review] > > patch part 1 - Add MediaResourceManager > > > > Review of attachment 8615978 [details] [diff] [review]: > > ----------------------------------------------------------------- > > > > You should also get an IPC peer to look at this. Maybe nical? > > > > Can you use MediaPromises here for async operations? We should use them for > > all async operations in new code if possible. > > I do not think it is a good idea to use MediaPromises here at this time. If > we use MediaPromise for async operation, caller side is also necessary to be > prepared to handle it. We could not assume it for all future use cases. In > future, Firefox OS TV might use this capability. But we do not know which > code uses this capability in which purpose. > > If callback is used, it is easy to connect to MediaPromise. It is already > done in this bug in MediaOMXReader and MediaCodecReader cases. OK. > > > > ::: dom/media/systemservices/PMediaResourceManager.ipdl > > @@ +11,5 @@ > > > +namespace mozilla { > > > +namespace media { > > > + > > > +/* > > > + * The PMediaResourceManager is a sub-protocol in PImageBridge > > > > Can we rename "*MediaResource*" to "*CodecResource*", so that it's clear > > that this is different from a MediaResource, i.e. the thing that we read > > data from? > > For example, Firefox OS TV might use this capability in ture, in this case, > we could not expect the resource is only CodecResource. Is there another > better name? Naming things is hard. MediaSystemResource, MediaHardwareResource?
Flags: needinfo?(cpearce)
> ::: dom/media/systemservices/MediaResourceManager.h >> @@ +71,5 @@ >> > + bool mShutDown; >> > + >> > + media::MediaResourceManagerChild* mChild; >> > + >> > + std::map<int32_t, MediaResourceClient*> mResourceClients; >> >> You should use nsRefPtrHashtable<nsUint32HashKey, MediaResourceClient> >> here, as that will addref/release the MediaResourceClients you put in. > >I'll update it. Correction: Here should not addref/release, MediaResourceClient's lifetime is controlled only by its user.
Apply the comment.
Attachment #8615978 - Attachment is obsolete: true
Attachment #8613668 - Attachment is obsolete: true
Attachment #8613097 - Attachment is obsolete: true
Attachment #8615979 - Attachment is obsolete: true
Fix debug build failures.
Attachment #8626803 - Attachment is obsolete: true
Attachment #8627221 - Flags: review?(nical.bugzilla)
Attachment #8627221 - Flags: review?(cpearce)
Summary: Impelement platform independent MediaResourceManager → Implement platform independent MediaResourceManager
Comment on attachment 8627221 [details] [diff] [review] patch part 1 - Add MediaResourceManager Review of attachment 8627221 [details] [diff] [review]: ----------------------------------------------------------------- Overall looks good. I would prefer to not have the synchronous acquires used in new code. We're trying to remove synchronous waits, as they're a source of bugs. New code (i.e. the Gonk backend for the MediaFormatReader, not the old MediaOmxReader) should be async, and it's easy to do now that we have MediaPromises. ::: dom/media/systemservices/MediaSystemResourceClient.h @@ +25,5 @@ > +}; > + > +/** > + * MediaSystemResourceClient is used to reserve a media resource like hw decoder. > + * When system has a limitation of a media resrouce, use this class s/resrouce/resource/ @@ +52,5 @@ > + // If the resource is used by others, wait until acquired. > + void Acquire(); > + > + // Try to acquire media resource synchronously. If the resource is not > + // available, fail to acquire it. If the resource is not *immediately* available... @@ +53,5 @@ > + void Acquire(); > + > + // Try to acquire media resource synchronously. If the resource is not > + // available, fail to acquire it. > + // return false if resource is not acquired. "return false if resource is not acquired." does not need to be said twice. @@ +56,5 @@ > + // available, fail to acquire it. > + // return false if resource is not acquired. > + // return false if resource is not acquired. > + // > + // This function should not be called on ImageBridge thread. Add a comment here saying that synchronous AcqureSyncNoWait() is only here for compatibility with legacy code, and that new code should use the async Acquire(). ::: dom/media/systemservices/MediaSystemResourceManager.cpp @@ +76,5 @@ > + return; > + } > + > + if (InImageBridgeChildThread()) { > + if (!sSingleton) { It's confusing that you call MediaSystemResourceManager::Init() which dispatches a task which calls MediaSystemResourceManager_InitSync which calls MediaSystemResourceManager::Init() to unblock the original thread waiting in MediaSystemResourceManager::Init(). Can't you just allocate MediaSystemResourceManager() in MediaSystemResourceManager_InitSync instead of calling back into MediaSystemResourceManager::Init() to allocate it? Or even, use a lambda for the task to allocate sSingleton from inside MediaSystemResourceManager::Init()? Like so: ReentrantMonitor barrier("MediaSystemResourceManager::Init"); ReentrantMonitorAutoEnter autoMon(barrier); bool done = false; nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([&]() { if (!sSingleton) { sSingleton = new MediaSystemResourceManager(); } ReentrantMonitorAutoEnter autoMon(barrier); done = true; barrier->NotifyAll(); }); ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( FROM_HERE, NewRunnableFunction(&task)); // should stop the thread until done. while (!done) { barrier.Wait(); } @@ +86,5 @@ > + sSingleton = new MediaSystemResourceManager(); > + } > + return; > + } > + ReentrantMonitor barrier("MediaSystemResourceManager::Init"); I don't see why you need another monitor here; why can't you use mReentrantMonitor? Whenever you lock the barrier monitor, you also lock mReentrantMonitor, so it doesn't seem necessary to track both monitors? @@ +198,5 @@ > +{ > + MOZ_ASSERT(aClient); > + MOZ_ASSERT(!InImageBridgeChildThread()); > + > + { You don't need the extra {} scope here; the function scope is sufficient to take the lock. ::: dom/media/systemservices/MediaSystemResourceManagerChild.h @@ +48,5 @@ > + virtual bool RecvResponse(const uint32_t& aId, > + const bool& aSuccess) override; > + > +private: > + virtual void ActorDestroy(ActorDestroyReason aActorDestroyReason) override; You only need one of "virtual" and "override" now, the Mozilla C++ Style guide no longer requires you to have both. ::: dom/media/systemservices/MediaSystemResourceManagerParent.cpp @@ +59,5 @@ > +MediaSystemResourceManagerParent::ActorDestroy(ActorDestroyReason aReason) > +{ > + MOZ_ASSERT(!mDestroyed); > + > + // Release all resource requests of the MediaSystemResourceManagerParent Also mention in your comment that this clears all remaining pointers to this object, so that there's no possibility of something trying to use-after-free this object. ::: dom/media/systemservices/MediaSystemResourceService.cpp @@ +99,5 @@ > + return; > + } > + > + // Try to acquire a resource > + if(resource->mAcquiredRequests.size() < resource->mResourceCount) if (...) { That is, space between "if" and "(", and "{" at the end of line, not start of following line. @@ +186,5 @@ > + return; > + } > + > + std::deque<MediaSystemResourceRequest>::iterator it; > + std::deque<MediaSystemResourceRequest>& acquiredRequests = You've written pretty much the same loop to erase a ResourceRequest from a std::deque<MediaSystemResourceRequest> four times in this class. I think you should have a helper function to do it.
Attachment #8627221 - Flags: review?(cpearce) → review+
Comment on attachment 8626808 [details] [diff] [review] patch part 4 - Change to OMXCodecProxy Review of attachment 8626808 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/omx/OMXCodecWrapper.cpp @@ +45,5 @@ > bool > OMXCodecReservation::ReserveOMXCodec() > { > + mClient = new mozilla::MediaSystemResourceClient(mType); > + return mClient->AcquireSyncNoWait(); // don't wait if resrouce is not available s/resrouce/resource/
(In reply to Chris Pearce (:cpearce) from comment #39) > > You should also get an IPC peer to look at this. Maybe nical? Oh my, I am doomed! Sotaro, could you add a comment at the top of the main classes involved in this patch, explaining what they do? I don't know this code and it isn't quite clear from a quick glance what a MediaResourceManager is for. Should help with the review and for people discovering this code in general.
(In reply to Chris Pearce (:cpearce) from comment #55) > Comment on attachment 8627221 [details] [diff] [review] > patch part 1 - Add MediaResourceManager > > Review of attachment 8627221 [details] [diff] [review]: > ----------------------------------------------------------------- > > Overall looks good. I would prefer to not have the synchronous acquires used > in new code. We're trying to remove synchronous waits, as they're a source > of bugs. New code (i.e. the Gonk backend for the MediaFormatReader, not the > old MediaOmxReader) should be async, and it's easy to do now that we have > MediaPromises. As in comment 42, sync api is necessary for WebRTC. MediaPromises does not work the webrtc use case. > > ::: dom/media/systemservices/MediaSystemResourceClient.h > @@ +25,5 @@ > > +}; > > + > > +/** > > + * MediaSystemResourceClient is used to reserve a media resource like hw decoder. > > + * When system has a limitation of a media resrouce, use this class > > s/resrouce/resource/ Update in a next patch. > > @@ +52,5 @@ > > + // If the resource is used by others, wait until acquired. > > + void Acquire(); > > + > > + // Try to acquire media resource synchronously. If the resource is not > > + // available, fail to acquire it. > > If the resource is not *immediately* available... Update in a next patch. > > @@ +53,5 @@ > > + void Acquire(); > > + > > + // Try to acquire media resource synchronously. If the resource is not > > + // available, fail to acquire it. > > + // return false if resource is not acquired. > > "return false if resource is not acquired." does not need to be said twice. Update in a next patch. > > @@ +56,5 @@ > > + // available, fail to acquire it. > > + // return false if resource is not acquired. > > + // return false if resource is not acquired. > > + // > > + // This function should not be called on ImageBridge thread. > > Add a comment here saying that synchronous AcqureSyncNoWait() is only here > for compatibility with legacy code, and that new code should use the async > Acquire(). As the above explanation, the function is not for media playback's legacy code. It is for WebRTC code and async api does not work for it. > > ::: dom/media/systemservices/MediaSystemResourceManager.cpp > @@ +76,5 @@ > > + return; > > + } > > + > > + if (InImageBridgeChildThread()) { > > + if (!sSingleton) { > > It's confusing that you call MediaSystemResourceManager::Init() which > dispatches a task which calls MediaSystemResourceManager_InitSync which > calls MediaSystemResourceManager::Init() to unblock the original thread > waiting in MediaSystemResourceManager::Init(). > > Can't you just allocate MediaSystemResourceManager() in > MediaSystemResourceManager_InitSync instead of calling back into > MediaSystemResourceManager::Init() to allocate it? > > Or even, use a lambda for the task to allocate sSingleton from inside > MediaSystemResourceManager::Init()? Like so: > > ReentrantMonitor barrier("MediaSystemResourceManager::Init"); > ReentrantMonitorAutoEnter autoMon(barrier); > bool done = false; > > nsCOMPtr<nsIRunnable> task = > NS_NewRunnableFunction([&]() { > if (!sSingleton) { > sSingleton = new MediaSystemResourceManager(); > } > ReentrantMonitorAutoEnter autoMon(barrier); > done = true; > barrier->NotifyAll(); > }); > > ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( > FROM_HERE, NewRunnableFunction(&task)); > > // should stop the thread until done. > while (!done) { > barrier.Wait(); > } I'll update in a next patch. > > @@ +86,5 @@ > > + sSingleton = new MediaSystemResourceManager(); > > + } > > + return; > > + } > > + ReentrantMonitor barrier("MediaSystemResourceManager::Init"); > > I don't see why you need another monitor here; why can't you use > mReentrantMonitor? Whenever you lock the barrier monitor, you also lock > mReentrantMonitor, so it doesn't seem necessary to track both monitors? It is because MediaSystemResourceManager::Init() is static function. It could be called before MediaSystemResourceManager instance creation. > > @@ +198,5 @@ > > +{ > > + MOZ_ASSERT(aClient); > > + MOZ_ASSERT(!InImageBridgeChildThread()); > > + > > + { > > You don't need the extra {} scope here; the function scope is sufficient to > take the lock. I'll update it in a next patch. In old patches, it was necessary. > > ::: dom/media/systemservices/MediaSystemResourceManagerChild.h > @@ +48,5 @@ > > + virtual bool RecvResponse(const uint32_t& aId, > > + const bool& aSuccess) override; > > + > > +private: > > + virtual void ActorDestroy(ActorDestroyReason aActorDestroyReason) override; > > You only need one of "virtual" and "override" now, the Mozilla C++ Style > guide no longer requires you to have both. I'll update it in a next patch. > > ::: dom/media/systemservices/MediaSystemResourceManagerParent.cpp > @@ +59,5 @@ > > +MediaSystemResourceManagerParent::ActorDestroy(ActorDestroyReason aReason) > > +{ > > + MOZ_ASSERT(!mDestroyed); > > + > > + // Release all resource requests of the MediaSystemResourceManagerParent > > Also mention in your comment that this clears all remaining pointers to this > object, so that there's no possibility of something trying to use-after-free > this object. Update in a next patch. > > ::: dom/media/systemservices/MediaSystemResourceService.cpp > @@ +99,5 @@ > > + return; > > + } > > + > > + // Try to acquire a resource > > + if(resource->mAcquiredRequests.size() < resource->mResourceCount) > > if (...) { > > That is, space between "if" and "(", and "{" at the end of line, not start > of following line. Update in a next patch. > > @@ +186,5 @@ > > + return; > > + } > > + > > + std::deque<MediaSystemResourceRequest>::iterator it; > > + std::deque<MediaSystemResourceRequest>& acquiredRequests = > > You've written pretty much the same loop to erase a ResourceRequest from a > std::deque<MediaSystemResourceRequest> four times in this class. I think you > should have a helper function to do it. Apply it in a next patch.
Comment on attachment 8627221 [details] [diff] [review] patch part 1 - Add MediaResourceManager Review of attachment 8627221 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/systemservices/MediaSystemResourceService.cpp @@ +186,5 @@ > + return; > + } > + > + std::deque<MediaSystemResourceRequest>::iterator it; > + std::deque<MediaSystemResourceRequest>& acquiredRequests = I re-checked the code, there are 4 time similar loop, but actually they are categorized to 2. Each has only 2 loops. Therefore, I think helper is not necessary.
Apply the comments.
Attachment #8627221 - Attachment is obsolete: true
Attachment #8627221 - Flags: review?(nical.bugzilla)
Attachment #8629003 - Flags: review?(nical.bugzilla)
Attachment #8629003 - Attachment description: patch part 1 - Add MediaResourceManager → patch part 1 - Add MediaResourceManager (r=cpearce)
rebased.
Attachment #8626804 - Attachment is obsolete: true
Attachment #8629077 - Flags: review?(nical.bugzilla)
rebased.
Attachment #8626806 - Attachment is obsolete: true
rebased.
Attachment #8626808 - Attachment is obsolete: true
Attachment #8629084 - Flags: review?(bwu)
Attachment #8629087 - Flags: review?(bwu)
Attachment #8613075 - Flags: review?(cpearce)
(In reply to Nicolas Silva [:nical] from comment #57) > Sotaro, could you add a comment at the top of the main classes involved in > this patch, explaining what they do? I don't know this code and it isn't > quite clear from a quick glance what a MediaResourceManager is for. Should > help with the review and for people discovering this code in general. I added some comments. And attachment 8615990 [details] (class diagram of MediaResourceManager) might help to understand the overview.
Attachment #8613075 - Flags: review?(cpearce) → review+
Comment on attachment 8629084 [details] [diff] [review] patch part 3 - Change to MediaCodecProxy Review of attachment 8629084 [details] [diff] [review]: ----------------------------------------------------------------- Looks good to me! It would be nice to add some comments to explicitly let users know for audio case it is required to use AskMediaCodecAndWait() instead of AsyncAskMediaCodec().
Attachment #8629084 - Flags: review?(bwu) → review+
Comment on attachment 8629087 [details] [diff] [review] patch part 4 - Change to OMXCodecProxy Review of attachment 8629087 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/omx/OMXCodecWrapper.cpp @@ +43,5 @@ > }; > > bool > OMXCodecReservation::ReserveOMXCodec() > { Should we check mClient is already assigned or not, like the original check for mManagerService?
Attachment #8629087 - Flags: review?(bwu) → review+
Comment on attachment 8629003 [details] [diff] [review] patch part 1 - Add MediaResourceManager (r=cpearce) Review of attachment 8629003 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/systemservices/MediaSystemResourceClient.h @@ +30,5 @@ > + virtual void ResourceReserveFailed() = 0; > +}; > + > +/** > + * MediaSystemResourceClient is used to reserve a media system resource nit: trailing space ::: dom/media/systemservices/MediaSystemResourceManager.cpp @@ +92,5 @@ > + > + ReentrantMonitor barrier("MediaSystemResourceManager::Init"); > + ReentrantMonitorAutoEnter autoMon(barrier); > + bool done = false; > + bit: trailing space @@ +105,5 @@ > + }); > + > + ImageBridgeChild::GetSingleton()->GetMessageLoop()->PostTask( > + FROM_HERE, new RunnableCallTask(runnable)); > + nit: trailing space ::: dom/media/systemservices/PMediaSystemResourceManager.ipdl @@ +23,5 @@ > + > +parent: > + async Acquire(uint32_t aId, MediaSystemResourceType aResourceType, bool aWillWait); > + async Release(uint32_t aId); > + async __delete__(); Is there something that guarantees that __delete__ cannot cross the Response message? In gfx, most of the times we have tried to send __delete__ from the child side, we've eventually run into this kind of issue and had to change the destruction sequence to have a Destroy message sent from child to parent answered by the __delete__ message from parent to child. If there is something in place (explicitly or implicitly) to prevent the issue in the case of PMediaSystemResourceManager, please explain it in a comment here. Issues with ipdl protocol shutdown keep coming back, so let's be careful and explicit about that part of the logic.
Attachment #8629003 - Flags: review?(nical.bugzilla) → review+
Attachment #8629077 - Flags: review?(nical.bugzilla) → review+
Apply the comment. Carry "r=bwu".
Attachment #8629084 - Attachment is obsolete: true
Attachment #8629376 - Flags: review+
Apply the comment. Carry "r=bwu".
Attachment #8629087 - Attachment is obsolete: true
Attachment #8629379 - Flags: review+
Comment on attachment 8629003 [details] [diff] [review] patch part 1 - Add MediaResourceManager (r=cpearce) Review of attachment 8629003 [details] [diff] [review]: ----------------------------------------------------------------- ::: dom/media/systemservices/PMediaSystemResourceManager.ipdl @@ +23,5 @@ > + > +parent: > + async Acquire(uint32_t aId, MediaSystemResourceType aResourceType, bool aWillWait); > + async Release(uint32_t aId); > + async __delete__(); Yhea, it seems better to change the __delete__ like PTexture.
Apply the comment. Carry "r=cpearce,nical".
Attachment #8629003 - Attachment is obsolete: true
Attachment #8629419 - Flags: review+
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
Depends on: 1200903
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: