Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9935bd49 authored by qinzhichao's avatar qinzhichao Committed by Andy Hung
Browse files

Fix issues crashing with Fatal signal when calling getFormat



when playing multimedia file, GenericSource::getTrackInfo run in the
NuPlayerDriver thread, and GenericSource::getFormatMeta run in the
Generic thread. they would access the critical resource which is
mMetaData in IMediaSource. There is no lock to protect mMetaData.
Occasionally, SIGSEGV occurs when mMetaData point to a new object.

Instead getting trackInfo in Generic thread.

Bug: 34220591
Signed-off-by: default avatarqinzhichao <qinzhichao@xiaomi.com>
parent 549e4319
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -691,6 +691,12 @@ void NuPlayer::GenericSource::onMessageReceived(const sp<AMessage> &msg) {
          break;
      }

      case kWhatGetTrackInfo:
      {
          onGetTrackInfo(msg);
          break;
      }

      case kWhatSelectTrack:
      {
          onSelectTrack(msg);
@@ -960,6 +966,34 @@ size_t NuPlayer::GenericSource::getTrackCount() const {
}

sp<AMessage> NuPlayer::GenericSource::getTrackInfo(size_t trackIndex) const {
    sp<AMessage> msg = new AMessage(kWhatGetTrackInfo, this);
    msg->setSize("trackIndex", trackIndex);

    sp<AMessage> response;
    sp<RefBase> format;
    status_t err = msg->postAndAwaitResponse(&response);
    if (err == OK && response != NULL) {
        CHECK(response->findObject("format", &format));
        return static_cast<AMessage*>(format.get());
    } else {
        return NULL;
    }
}

void NuPlayer::GenericSource::onGetTrackInfo(const sp<AMessage>& msg) const {
    size_t trackIndex;
    CHECK(msg->findSize("trackIndex", &trackIndex));

    sp<AMessage> response = new AMessage;
    sp<AMessage> format = doGetTrackInfo(trackIndex);
    response->setObject("format", format);

    sp<AReplyToken> replyID;
    CHECK(msg->senderAwaitsResponse(&replyID));
    response->postReply(replyID);
}

sp<AMessage> NuPlayer::GenericSource::doGetTrackInfo(size_t trackIndex) const {
    size_t trackCount = mSources.size();
    if (trackIndex >= trackCount) {
        return NULL;
+3 −0
Original line number Diff line number Diff line
@@ -251,6 +251,9 @@ private:
    void onGetFormatMeta(const sp<AMessage>& msg) const;
    sp<MetaData> doGetFormatMeta(bool audio) const;

    void onGetTrackInfo(const sp<AMessage>& msg) const;
    sp<AMessage> doGetTrackInfo(size_t trackIndex) const;

    void onGetSelectedTrack(const sp<AMessage>& msg) const;
    ssize_t doGetSelectedTrack(media_track_type type) const;