Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] Refactor media_session_client #2599

Closed
wants to merge 1 commit into from

Conversation

zhongqiliang
Copy link
Contributor

@zhongqiliang zhongqiliang commented Mar 14, 2024

  1. removed mutex lock in OnMediaSessionStateChanged() in android_media_session_client.cc since it does nothing in the mutex block.
  2. removed if (ext_image.src == nullptr) check in OnMediaSessionStateChanged() in media_session_client.cc as media_image.src().c_str() should never return nullptr.
  3. earlier return when if (extension_ && extension_->version >= 1) check failed
  4. created ext_artwork with vector instead of array.

b/329330347

@datadog-cobalt-youtube
Copy link

datadog-cobalt-youtube bot commented Mar 14, 2024

Datadog Report

Branch report: b-329330347-media_session_client
Commit report: 7985305
Test service: cobalt

✅ 0 Failed, 30191 Passed, 1 Skipped, 14m 25.36s Wall Time

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 5.12821% with 37 lines in your changes are missing coverage. Please review.

Project coverage is 58.88%. Comparing base (c65b33a) to head (7985305).
Report is 109 commits behind head on main.

Files Patch % Lines
cobalt/media_session/media_session_client.cc 5.12% 37 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2599      +/-   ##
==========================================
+ Coverage   58.17%   58.88%   +0.70%     
==========================================
  Files        1788     1904     +116     
  Lines       84294    93310    +9016     
==========================================
+ Hits        49038    54941    +5903     
- Misses      35256    38369    +3113     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zhongqiliang zhongqiliang force-pushed the b-329330347-media_session_client branch 2 times, most recently from 6f95614 to c88ef38 Compare March 14, 2024 23:13
@zhongqiliang zhongqiliang force-pushed the b-329330347-media_session_client branch from c88ef38 to 979923c Compare March 15, 2024 00:10
@zhongqiliang zhongqiliang force-pushed the b-329330347-media_session_client branch 2 times, most recently from 14baea6 to d7cc04c Compare March 22, 2024 17:31
@sideb0ard
Copy link
Contributor

I'm always a bit reluctant to add a mutex if it can be avoided.
If the issue here is that the reference to MediaMetadataInit goes out of scope, at https://source.corp.google.com/h/lbshell-internal/cobalt_src/+/COBALT:cobalt/media_session/media_session_client.cc;l=325;drc=dff48f461fe8b269ff79460332dbd5d258262b99;bpv=1;bpt=0 - could we just take a copy of MediaMetadataInit?

@zhongqiliang
Copy link
Contributor Author

From here, https://source.corp.google.com/h/lbshell-internal/cobalt_src/+/COBALT:cobalt/media_session/media_session.cc;l=99-114?q=p:cobalt%20UpdateMediaSessionState, do we know if UpdateMediaSessionState() can be called on multiple threads? If this is the case, I feel there could be a chance that 1 thread is reading session_state_ fields inside OnMediaSessionStateChanged https://source.corp.google.com/h/lbshell-internal/cobalt_src/+/COBALT:cobalt/media_session/media_session_client.cc;l=300-350, while the other thread can rewrite session_state_ here https://source.corp.google.com/h/lbshell-internal/cobalt_src/+/COBALT:cobalt/media_session/media_session_client.cc;l=275-278. Thoughts?

@xiaomings xiaomings changed the title Fix crash caused by Use after free [android] Fix crash in MediaSessionClient::OnMediaSessionStateChanged() Mar 26, 2024
@sideb0ard
Copy link
Contributor

do we know if UpdateMediaSessionState() can be called on multiple threads?

It doesn't look like it.
I see it being called twice, once in media_session_client which DCHECKs its on the media_session_->task_runner_, and once in media_session which also checks its on the task_runner_->BelongsToCurrentThread()

@zhongqiliang
Copy link
Contributor Author

I see, thank you. One thing to confirm, "If the issue here is that the reference to MediaMetadataInit goes out of scope", do you meant the ext_image object here, https://source.corp.google.com/h/lbshell-internal/cobalt_src/+/COBALT:cobalt/media_session/media_session_client.cc;l=333, is it?

@zhongqiliang zhongqiliang force-pushed the b-329330347-media_session_client branch 5 times, most recently from 31b5462 to 1d5687f Compare March 26, 2024 22:52
ext_image is released after the for loop, do not create it, write
directly to the ext_artwork array.

b/329330347
@zhongqiliang zhongqiliang force-pushed the b-329330347-media_session_client branch from 1d5687f to 7985305 Compare March 27, 2024 21:28
@zhongqiliang zhongqiliang changed the title [android] Fix crash in MediaSessionClient::OnMediaSessionStateChanged() [android] Refactor media_session_client Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants