From a1df816c0677185534babba6ffc29970b048e52e Mon Sep 17 00:00:00 2001 From: Lajos Molnar Date: Thu, 3 Apr 2014 19:13:01 -0700 Subject: [PATCH] stagefright: log uri protocols, and opt-in to log full uri Added property media.stagefright.log-uri. Set it to true or 1 to log uris by AwesomePlayer. Added utility function to get uri debug string based on incognito and log opt-in status. Change-Id: I5ccc23079ddfb120dd9703a3ed651a162ed5acec Related-Bug: 6994761 --- include/media/stagefright/Utils.h | 2 ++ media/libstagefright/AwesomePlayer.cpp | 4 +-- media/libstagefright/Utils.cpp | 36 +++++++++++++++++++++++++++ media/libstagefright/httplive/LiveSession.cpp | 9 +++---- media/libstagefright/httplive/M3UParser.cpp | 3 ++- media/libstagefright/rtsp/ARTSPConnection.cpp | 2 +- media/libstagefright/rtsp/SDPLoader.cpp | 7 ++---- 7 files changed, 48 insertions(+), 15 deletions(-) diff --git a/include/media/stagefright/Utils.h b/include/media/stagefright/Utils.h index bbad271412..c85368fee8 100644 --- a/include/media/stagefright/Utils.h +++ b/include/media/stagefright/Utils.h @@ -60,6 +60,8 @@ status_t sendMetaDataToHal(sp& sink, const sp& meta, bool hasVideo, bool isStreaming, audio_stream_type_t streamType); +AString uriDebugString(const AString &uri, bool incognito = false); + } // namespace android #endif // UTILS_H_ diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index 4bad14b561..e92407608d 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -310,7 +310,7 @@ status_t AwesomePlayer::setDataSource_l( } } - ALOGI("setDataSource_l(URL suppressed)"); + ALOGI("setDataSource_l(%s)", uriDebugString(mUri, mFlags & INCOGNITO).c_str()); // The actual work will be done during preparation in the call to // ::finishSetDataSource_l to avoid blocking the calling thread in @@ -2823,7 +2823,7 @@ status_t AwesomePlayer::dump( fprintf(out, " AwesomePlayer\n"); if (mStats.mFd < 0) { - fprintf(out, " URI(suppressed)"); + fprintf(out, " URI(%s)", uriDebugString(mUri, mFlags & INCOGNITO).c_str()); } else { fprintf(out, " fd(%d)", mStats.mFd); } diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp index 4ff805fbca..047fac7101 100644 --- a/media/libstagefright/Utils.cpp +++ b/media/libstagefright/Utils.cpp @@ -17,6 +17,7 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "Utils" #include +#include #include "include/ESDS.h" @@ -628,5 +629,40 @@ bool canOffloadStream(const sp& meta, bool hasVideo, return AudioSystem::isOffloadSupported(info); } +AString uriDebugString(const AString &uri, bool incognito) { + if (incognito) { + return AString(""); + } + + char prop[PROPERTY_VALUE_MAX]; + if (property_get("media.stagefright.log-uri", prop, "false") && + (!strcmp(prop, "1") || !strcmp(prop, "true"))) { + return uri; + } + + // find scheme + AString scheme; + const char *chars = uri.c_str(); + for (size_t i = 0; i < uri.size(); i++) { + const char c = chars[i]; + if (!isascii(c)) { + break; + } else if (isalpha(c)) { + continue; + } else if (i == 0) { + // first character must be a letter + break; + } else if (isdigit(c) || c == '+' || c == '.' || c =='-') { + continue; + } else if (c != ':') { + break; + } + scheme = AString(uri, 0, i); + scheme.append("://"); + return scheme; + } + return AString(""); +} + } // namespace android diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp index fd42e77da6..08a146f1d5 100644 --- a/media/libstagefright/httplive/LiveSession.cpp +++ b/media/libstagefright/httplive/LiveSession.cpp @@ -477,11 +477,8 @@ void LiveSession::onConnect(const sp &msg) { headers = NULL; } -#if 1 - ALOGI("onConnect "); -#else - ALOGI("onConnect %s", url.c_str()); -#endif + // TODO currently we don't know if we are coming here from incognito mode + ALOGI("onConnect %s", uriDebugString(url).c_str()); mMasterURL = url; @@ -489,7 +486,7 @@ void LiveSession::onConnect(const sp &msg) { mPlaylist = fetchPlaylist(url.c_str(), NULL /* curPlaylistHash */, &dummy); if (mPlaylist == NULL) { - ALOGE("unable to fetch master playlist ."); + ALOGE("unable to fetch master playlist %s.", uriDebugString(url).c_str()); postPrepared(ERROR_IO); return; diff --git a/media/libstagefright/httplive/M3UParser.cpp b/media/libstagefright/httplive/M3UParser.cpp index f22d650de8..785c515f52 100644 --- a/media/libstagefright/httplive/M3UParser.cpp +++ b/media/libstagefright/httplive/M3UParser.cpp @@ -798,7 +798,8 @@ status_t M3UParser::parseCipherInfo( if (MakeURL(baseURI.c_str(), val.c_str(), &absURI)) { val = absURI; } else { - ALOGE("failed to make absolute url for ."); + ALOGE("failed to make absolute url for %s.", + uriDebugString(baseURI).c_str()); } } diff --git a/media/libstagefright/rtsp/ARTSPConnection.cpp b/media/libstagefright/rtsp/ARTSPConnection.cpp index cc3b63c7be..f25539c336 100644 --- a/media/libstagefright/rtsp/ARTSPConnection.cpp +++ b/media/libstagefright/rtsp/ARTSPConnection.cpp @@ -239,7 +239,7 @@ void ARTSPConnection::onConnect(const sp &msg) { // right here, since we currently have no way of asking the user // for this information. - ALOGE("Malformed rtsp url "); + ALOGE("Malformed rtsp url %s", uriDebugString(url).c_str()); reply->setInt32("result", ERROR_MALFORMED); reply->post(); diff --git a/media/libstagefright/rtsp/SDPLoader.cpp b/media/libstagefright/rtsp/SDPLoader.cpp index 09f7eee58a..424badf97e 100644 --- a/media/libstagefright/rtsp/SDPLoader.cpp +++ b/media/libstagefright/rtsp/SDPLoader.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #define DEFAULT_SDP_SIZE 100000 @@ -89,11 +90,7 @@ void SDPLoader::onLoad(const sp &msg) { KeyedVector *headers = NULL; msg->findPointer("headers", (void **)&headers); - if (!(mFlags & kFlagIncognito)) { - ALOGV("onLoad '%s'", url.c_str()); - } else { - ALOGI("onLoad "); - } + ALOGV("onLoad %s", uriDebugString(url, mFlags & kFlagIncognito).c_str()); if (!mCancelled) { err = mHTTPDataSource->connect(url.c_str(), headers); -- 2.11.0