MyHandler.h對消息"accu"的處理

  下面貼出安卓N版本MyHandler.h對消息”accu”的處理原文 
  

            //收到'accu'消息,說明AAVCAssembler成功將多個NAL單元組合成了一幀完整的數據,並將存放該幀數據的buffer的引用添加到該buffer裏了。
            case 'accu':
            {
                if (mSeekPending) {
                    ALOGV("Stale access unit.");
                    break;
                }

                int32_t timeUpdate;
                if (msg->findInt32("time-update", &timeUpdate) && timeUpdate) {
                    //如果在消息msg裏設置了"time-update"字段信息,並且得到的timeUpdate值非零,則需要進行處理
                    //從消息msg裏設置的"track-index"字段信息得到trackIndex的值
                    //從消息msg裏設置的"rtp-time"字段信息得到rtpTime的值
                    //從消息msg裏設置的"ntp-time"字段信息得到ntpTime的值
                    //調用onTimeUpdate(trackIndex, rtpTime, ntpTime)進行處理
                    //break跳出該case處理分支
                    size_t trackIndex;
                    CHECK(msg->findSize("track-index", &trackIndex));

                    uint32_t rtpTime;
                    uint64_t ntpTime;
                    CHECK(msg->findInt32("rtp-time", (int32_t *)&rtpTime));
                    CHECK(msg->findInt64("ntp-time", (int64_t *)&ntpTime));

                    onTimeUpdate(trackIndex, rtpTime, ntpTime);
                    break;
                }

                int32_t first;
                if (msg->findInt32("first-rtcp", &first)) {
                    //如果消息msg裏設置了"first-rtcp"字段信息則將mReceivedFirstRTCPPacket的值設置爲true
                    //break跳出該case語句處理分支
                    mReceivedFirstRTCPPacket = true;
                    break;
                }

                if (msg->findInt32("first-rtp", &first)) {
                    //如果消息msg裏設置了"first-rtp"字段信息,則將mReceivedFirstRTPPacket的值設置爲true
                    //break跳出該case語句處理分支
                    mReceivedFirstRTPPacket = true;
                    break;
                }

                //代碼執行到這裏說明收到的是正常的一幀數據
                //將mNumAccessUnitsReceived自增1計數已經收到的幀的數量
                //調用postAccessUnitTimeoutCheck進行超時檢查
                ++mNumAccessUnitsReceived;
                postAccessUnitTimeoutCheck();


                //從消息msg的字段信息"track-index"得到trackIndex的值
                size_t trackIndex;
                CHECK(msg->findSize("track-index", &trackIndex));

                if (trackIndex >= mTracks.size()) {
                    //mTracks.size()表示的是支持的最大軌道數目,trackIndex不同超過這個值
                    //trackIndex在0~mTracks.size()-1內
                    ALOGV("late packets ignored.");
                    break;
                }

                //由trackIndex得到對應軌道的TrackInfo信息結構體的指針
                TrackInfo *track = &mTracks.editItemAt(trackIndex);

                int32_t eos;
                if (msg->findInt32("eos", &eos)) {
                    //如果消息msg設置了"eos"字段信息,說明該幀位位結尾幀
                    //當收到的幀是結尾幀的時候進行相應處理
                    //這裏具體的處理就先不介紹了先放一邊,抓住主要矛盾先
                    ALOGI("received BYE on track index %zu", trackIndex);
                    char value[PROPERTY_VALUE_MAX] = {0};
                    if (property_get("rtcp.bye.notify", value, "false")
                            && !strcasecmp(value, "true")) {
                        sp<AMessage> msg = mNotify->dup();
                        msg->setInt32("what", kWhatByeReceived);
                        msg->post();
                    }
                    if (!mAllTracksHaveTime && dataReceivedOnAllChannels()) {
                        ALOGI("No time established => fake existing data");

                        track->mEOSReceived = true;
                        mTryFakeRTCP = true;
                        mReceivedFirstRTCPPacket = true;
                        fakeTimestamps();
                    } else {
                        postQueueEOS(trackIndex, ERROR_END_OF_STREAM);
                    }
                    return;
                }

                if (mSeekPending) {
                    ALOGV("we're seeking, dropping stale packet.");
                    break;
                }

                /從消息msg裏的"access-unit"字段信息得到存放數據幀buffer的引用
                //調用onAccessUnitComplete(trackIndex, accessUnit)對該buffer進行處理
                sp<ABuffer> accessUnit;
                CHECK(msg->findBuffer("access-unit", &accessUnit));
                onAccessUnitComplete(trackIndex, accessUnit);
                break;
            }

  小結:MyHandler對消息”accu”的處理是:收到正常的數據幀的做法從消息msg裏的”access-unit”字段信息得到存放數據幀buffer的引用,然後調用onAccessUnitComplete(trackIndex, accessUnit)進行處理

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章