android4.2 WifiDisplay远程显示修改为保存文件

时间:2021-09-08 16:41:57

media\libstagefright\wifi-display\source\

编码那一块

\pizza\frameworks\av\media\libstagefright\wifi-display\source\Converter.h

// Utility class that receives media access units and converts them into
// media access unit of a different format.
// Right now this'll convert raw video into H.264 and raw audio into AAC.
struct Converter : public AHandler {
    Converter(
            const sp<AMessage> &notify,
            const sp<ALooper> &codecLooper,
            const sp<AMessage> &format,
            bool usePCMAudio,
            bool isRecordingScreen);

bool mIsRecordingScreen;

 

pizza\frameworks\av\media\libstagefright\wifi-display\source\Converter.cpp

 

 

Converter::Converter(
        const sp<AMessage> &notify,
        const sp<ALooper> &codecLooper,
        const sp<AMessage> &format,
        bool usePCMAudio,
        bool isRecordingScreen)
    : mInitCheck(NO_INIT),
      mNotify(notify),
      mCodecLooper(codecLooper),
      mInputFormat(format),
      mIsVideo(false),
      mIsPCMAudio(usePCMAudio),
      mNeedToManuallyPrependSPSPPS(false),
      mDoMoreWorkPending(false)
#if ENABLE_SILENCE_DETECTION
      ,mFirstSilentFrameUs(-1ll)
      ,mInSilentMode(false)
#endif
    {
    AString mime;
    CHECK(mInputFormat->findString("mime", &mime));
    mIsRecordingScreen = isRecordingScreen;
    if (!strncasecmp("video/", mime.c_str(), 6)) {
        mIsVideo = true;
    }

    CHECK(!usePCMAudio || !mIsVideo);

    mInitCheck = initEncoder();

    if (mInitCheck != OK) {
        if (mEncoder != NULL) {
            mEncoder->release();
            mEncoder.clear();
        }
    }
}

void Converter::shutdownAsync() {
    ALOGV("shutdown");
    if(!mIsRecordingScreen)
    {
         (new AMessage(kWhatShutdown, id()))->post();
         return;
    }

#if 1 //{     
    if (mEncoder != NULL) {
          mEncoder->release();
          mEncoder.clear();
    }
#endif //}
       
}

pizza\frameworks\av\media\libstagefright\wifi-display\source\MediaPuller.cpp

  这里是读取数据的源泉。

void MediaPuller::onMessageReceived(const sp<AMessage> &msg) {
    switch (msg->what()) {
        case kWhatStart:
        {
            status_t err;
            if (mIsAudio) {
                // This atrocity causes AudioSource to deliver absolute
                // systemTime() based timestamps (off by 1 us).
                sp<MetaData> params = new MetaData;
                params->setInt64(kKeyTime, 1ll);
                err = mSource->start(params.get());
            } else {
                sp<MetaData> params = new MetaData;

// 是不是将关键帧设置了只有三个
                 params->setInt32(kKeyNumBuffers,3 );
                err = mSource->start(params.get());
            }

case kWhatPull:
{
    int32_t generation;
    CHECK(msg->findInt32("generation", &generation));

    if (generation != mPullGeneration) {
        break;
    }

    MediaBuffer *mbuf;
    status_t err = mSource->read(&mbuf);

    if (mPaused) {
        if (err == OK) {
            mbuf->release();
            mbuf = NULL;
        }

        schedulePull();
        break;
    }

 

pizza\frameworks\av\media\libstagefright\wifi-display\source\PlaybackSession.h

  负责管理wifidisplay当中的RTP/RTCP的网络连接

PlaybackSession(
        const sp<ANetworkSession> &netSession,
        const sp<AMessage> &notify,
        const struct in_addr &interfaceAddr,
        const sp<IHDCP> &hdcp,
        int      width=0,
        int          height=0,
        bool         isRecordingScreen=false,
        WifiDisplaySource *wifiDisplaySource=NULL);

PlaybackSession(
        const sp<ANetworkSession> &netSession,
        const sp<AMessage> &notify,
        const struct in_addr &interfaceAddr,
        const sp<IHDCP> &hdcp,
        int   width=0,
        int   height=0,
        WifiDisplaySource *wifiDisplaySource=NULL);

status_t initEx(
          const char *clientIP, int32_t clientRtp, int32_t clientRtcp,
          Sender::TransportMode transportMode,
          bool usePCMAudio, char *outfile);

bool mIsRecordingScreen;
WifiDisplaySource *mWifiDisplaySource;

 

pizza\frameworks\av\media\libstagefright\wifi-display\source\Sender.h

#include "WifiDisplaySource.h"

struct WifiDisplaySource;

Sender(const sp<ANetworkSession> &netSession, const sp<AMessage> &notify, char *outfile, WifiDisplaySource *wifiDisplaySource);

bool mIsRecordingScreen;
WifiDisplaySource *mWifiDisplaySource;

 

//#if LOG_TRANSPORT_STREAM
    FILE *mLogFile;
//#endif
     char mOutFile[1024];
    char mRecBuf[1024 * 10];

 

status_t sendTsPacket(int32_t sessionID, const void *data, size_t size);

pizza\frameworks\av\media\libstagefright\wifi-display\source\TSPacketizer.cpp

  转换成TS数据流

pizza\frameworks\av\media\libstagefright\wifi-display\source\WifiDisplaySource.h

  wifidisplay的总管理

status_t startRecord(const char *iface);

status_t record(char *data, int len);

enum {
    kWhatStart,
    kWhatRTSPNotify,
    kWhatStop,
    kWhatPause,
    kWhatResume,
    kWhatReapDeadClients,
    kWhatPlaybackSessionNotify,
    kWhatKeepAlive,
    kWhatHDCPNotify,
    kWhatFinishStop2,
    kWhatTeardownTriggerTimedOut,
    kWhatStartRecord,
    kWhatSetupRecord,
    kWhatRecord,
    kWhatStopRecord,

};

    status_t onSetupRequestEx(char *outfile);
    status_t onPlayRequest(
            int32_t sessionID,
            int32_t cseq,
            const sp<ParsedMessage> &data);
    status_t onPlayRequestEx();
    status_t onPauseRequest(
            int32_t sessionID,
            int32_t cseq,
            const sp<ParsedMessage> &data);
   status_t onPauseRequestEx();
    status_t onTeardownRequest(
            int32_t sessionID,
            int32_t cseq,
            const sp<ParsedMessage> &data);

    status_t onTeardownRequestEx();
    void setOutputFile(const char *filename);

pizza\frameworks\av\media\libstagefright\wifi-display\ANetworkSession.cpp

  将转发到

status_t sendTsPacket(const void *data, ssize_t size);

void     setRtpSink(RTPSink* rtpsink);

ANetworkSession *mNetworkSession;
    sp<RTPSink> mRTPSink;