Changeset 102


Ignore:
Timestamp:
08/24/10 19:27:38 (18 months ago)
Author:
shiretu
Message:

-- added bandwidth filter

Location:
trunk/sources
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/androidapplestreaming/include/api.h

    r90 r102  
    3737Variant ContextCloseAll(); 
    3838 
     39Variant CommandSetBitrates(uint32_t contextId, string bitRates); 
    3940Variant CommandPlay(uint32_t contextId, string connectingString); 
    4041Variant CommandPlay(uint32_t contextId, string m3u8Uri, string httpSessionId, 
  • trunk/sources/androidapplestreaming/include/jniwrapper.h

    r90 r102  
    4545extern "C" jobject Java_com_rtmpd_CommandsInterface_ContextCloseAll( 
    4646                JNIEnv* pEnv, jobject thiz); 
     47extern "C" jobject Java_com_rtmpd_CommandsInterface_CommandSetBitrates( 
     48                JNIEnv* pEnv, jobject thiz, jint contextId, jstring bitrates); 
    4749extern "C" jobject Java_com_rtmpd_CommandsInterface_CommandPlay( 
    4850                JNIEnv* pEnv, jobject thiz, jint contextId, jstring m3u8Uri, 
  • trunk/sources/androidapplestreaming/src/api.cpp

    r96 r102  
    253253} 
    254254 
     255Variant CommandSetBitrates(uint32_t contextId, string bitRates) { 
     256        replace(bitRates, "[", ""); 
     257        replace(bitRates, "]", ""); 
     258        vector<string> parts; 
     259        split(bitRates, ",", parts); 
     260 
     261        vector<uint32_t> bws; 
     262        for (uint32_t i = 0; i < parts.size(); i++) { 
     263                string strBw = parts[i]; 
     264                trim(strBw); 
     265                if (strBw == "") 
     266                        continue; 
     267                uint32_t bw = (uint32_t) atol(STR(strBw)); 
     268                ADD_VECTOR_END(bws, bw); 
     269        } 
     270 
     271        Variant request; 
     272        ASC_REQ_BUILD_COMMAND_SET_BITRATES(request, contextId, bws); 
     273        Variant response; 
     274        SEND_VARIANT_REQUEST(request, response); 
     275        return response; 
     276} 
     277 
    255278Variant CommandPlay(uint32_t contextId, string connectingString) { 
    256279        vector<string> parts; 
  • trunk/sources/androidapplestreaming/src/jniwrapper.cpp

    r90 r102  
    8080} 
    8181 
     82extern "C" jobject Java_com_rtmpd_CommandsInterface_CommandSetBitrates( 
     83                JNIEnv* pEnv, jobject thiz, jint contextId, jstring bitrates) { 
     84        Variant result = CommandSetBitrates( 
     85                        (uint32_t) contextId, 
     86                        pEnv->GetStringUTFChars(bitrates, NULL)); 
     87        return VariantToJObject(result, pEnv); 
     88} 
     89 
    8290extern "C" jobject Java_com_rtmpd_CommandsInterface_CommandPlay( 
    8391                JNIEnv* pEnv, jobject thiz, jint contextId, jstring m3u8Uri, 
  • trunk/sources/androidapplestreaming/src/main.cpp

    r96 r102  
    124124 
    125125        uint32_t contextId = (uint32_t) ASC_RES_PARAM(result, "contextId"); 
     126        result = CommandSetBitrates(contextId, " [800000]"); 
     127        FINEST("result:\n%s", STR(result.ToString())); 
     128 
    126129        result = CommandPlay(contextId, MY_URL, MY_SESSION_ID, MY_KEY); 
    127130        FINEST("result:\n%s", STR(result.ToString())); 
  • trunk/sources/applications/applestreamingclient/include/clientcontext.h

    r96 r102  
    7070        StreamsManager *_pStreamsManager; 
    7171        double _lastWallClock; 
     72        map<uint32_t, uint32_t> _allowedBitrates; 
    7273private: 
    7374        ClientContext(); 
     
    101102        uint32_t GetCurrentChunkIndex(); 
    102103        AppleStreamingClientApplication *GetApplication(); 
     104        void SetAllowedBitrates(map<uint32_t, uint32_t> allowedBitrates); 
    103105 
    104106        //processing 
  • trunk/sources/applications/applestreamingclient/include/protocols/variant/messagestructure.h

    r80 r102  
    2929 
    3030#define ASC_REQ_TYPE_COMMAND_PLAY                               "commandPlay" 
     31#define ASC_REQ_TYPE_COMMAND_SET_BITRATES               "commandSetBitrates" 
    3132#define ASC_REQ_TYPE_COMMAND_PAUSE                              "commandPause" 
    3233#define ASC_REQ_TYPE_COMMAND_RESUME                             "commandResume" 
     
    4041#define ASC_REQ_TYPE_INFO_PLAYBACK                              "infoPlayback" 
    4142 
     43#define ASC_REQ_COMMAND_SET_BITRATES_BITRATES           "bitrates" 
    4244#define ASC_REQ_COMMAND_PLAY_URI_KEY                            "uri" 
    4345#define ASC_REQ_COMMAND_PLAY_SESSION_ID_KEY                     "sessionId" 
     
    8890#define ASC_REQ_PARAMS(v)                                       ASC_REQ(v)["parameters"] 
    8991#define ASC_REQ_PARAM(v,key)                            ASC_REQ_PARAMS(v)[(key)] 
     92#define ASC_REQ_COMMAND_SET_BITRATES_BWS(v)     ASC_REQ_PARAM(v,ASC_REQ_COMMAND_SET_BITRATES_BITRATES) 
    9093#define ASC_REQ_COMMAND_PLAY_URI(v)                     ASC_REQ_PARAM(v,ASC_REQ_COMMAND_PLAY_URI_KEY) 
    9194#define ASC_REQ_COMMAND_PLAY_SESSION_ID(v)      ASC_REQ_PARAM(v,ASC_REQ_COMMAND_PLAY_SESSION_ID_KEY) 
     
    126129        ASC_REQ_BUILD(v,ASC_REQ_TYPE_CONTEXT_CLOSE_ALL,0,Variant()) 
    127130 
     131#define ASC_REQ_BUILD_COMMAND_SET_BITRATES(v,contextId,bws) \ 
     132do { \ 
     133        Variant parameters; \ 
     134        parameters[ASC_REQ_COMMAND_SET_BITRATES_BITRATES].IsArray(true); \ 
     135        for(uint32_t i=0;i<bws.size();i++) { \ 
     136                parameters[ASC_REQ_COMMAND_SET_BITRATES_BITRATES].PushToArray((uint32_t)bws[i]); \ 
     137        } \ 
     138        ASC_REQ_BUILD(v,ASC_REQ_TYPE_COMMAND_SET_BITRATES,contextId,parameters); \ 
     139} while(0) 
     140 
    128141#define ASC_REQ_BUILD_COMMAND_PLAY(v,contextId,uri,sessionId,keyPassword) \ 
    129142do { \ 
  • trunk/sources/applications/applestreamingclient/include/protocols/variant/variantappprotocolhandler.h

    r74 r102  
    3939        void ProcessContextClose(BaseVariantProtocol *pProtocol, Variant &request); 
    4040        void ProcessContextCloseAll(BaseVariantProtocol *pProtocol, Variant &request); 
     41        void ProcessCommandSetBitrates(BaseVariantProtocol *pProtocol, Variant &request); 
    4142        void ProcessCommandPlay(BaseVariantProtocol *pProtocol, Variant &request); 
    4243        void ProcessCommandPause(BaseVariantProtocol *pProtocol, Variant &request); 
  • trunk/sources/applications/applestreamingclient/src/clientcontext.cpp

    r96 r102  
    219219} 
    220220 
     221void ClientContext::SetAllowedBitrates(map<uint32_t, uint32_t> allowedBitrates) { 
     222        _allowedBitrates = allowedBitrates; 
     223} 
     224 
    221225bool ClientContext::StartProcessing() { 
    222226        //1. Parse the connecting string and split it into usable pieces 
     
    283287        Playlist *pPlaylist = _childPlaylists[optimalBw]; 
    284288 
    285         if (_currentItemIndex == 0) 
    286                 _currentItemIndex = pPlaylist->GetItemsCount() / 2 + 10; 
     289        //      if (_currentItemIndex == 0) 
     290        //              _currentItemIndex = pPlaylist->GetItemsCount() / 2 + 10; 
    287291 
    288292        //4. Is this the last item in the playlis? 
     
    391395 
    392396uint32_t ClientContext::GetOptimalBw() { 
    393         //      if (_optimalBw == 0) { 
    394         //              _optimalBw = MAP_KEY(_childPlaylists.begin()); 
    395         //      } 
    396         _optimalBw = 800000; 
     397        if (_optimalBw == 0) { 
     398                _optimalBw = MAP_KEY(_childPlaylists.begin()); 
     399        } 
     400        //_optimalBw = 800000; 
    397401        return _optimalBw; 
    398402} 
     
    467471                if (bw < 10000) 
    468472                        bw *= 1024; 
     473                if (_allowedBitrates.size() > 0) { 
     474                        if (!MAP_HAS1(_allowedBitrates, bw)) { 
     475                                WARN("Skipping bitrate %d", bw); 
     476                                continue; 
     477                        } 
     478                } 
    469479                string uri = _pMasterPlaylist->GetItemUri(i); 
    470480 
     
    530540 
    531541bool ClientContext::SignalSpeedDetected(double instantAmount, double instantTime) { 
    532         //      FINEST("instantAmount: %.2f; instantTime: %.8f; Speed: %.2f KB/s", 
    533         //                      instantAmount, instantTime, instantAmount / instantTime / 1024); 
    534         _pSpeedComputer->PushAmount(instantAmount, instantTime); 
    535         double meanSpeed = _pSpeedComputer->GetMeanSpeed(); 
    536  
    537         uint32_t before = _optimalBw; 
    538         meanSpeed *= 8.0; 
    539         //      if (((aaa++) % 200) == 0) { 
    540         //              double ms = meanSpeed / 1024.00 / 8; 
    541         //              string um = "KB/s"; 
    542         //              if (ms > 1024) { 
    543         //                      ms = ms / 1024.00; 
    544         //                      um = "MB/s"; 
     542        //      //      FINEST("instantAmount: %.2f; instantTime: %.8f; Speed: %.2f KB/s", 
     543        //      //                      instantAmount, instantTime, instantAmount / instantTime / 1024); 
     544        //      _pSpeedComputer->PushAmount(instantAmount, instantTime); 
     545        //      double meanSpeed = _pSpeedComputer->GetMeanSpeed(); 
     546        // 
     547        //      uint32_t before = _optimalBw; 
     548        //      meanSpeed *= 8.0; 
     549        //      //      if (((aaa++) % 200) == 0) { 
     550        //      //              double ms = meanSpeed / 1024.00 / 8; 
     551        //      //              string um = "KB/s"; 
     552        //      //              if (ms > 1024) { 
     553        //      //                      ms = ms / 1024.00; 
     554        //      //                      um = "MB/s"; 
     555        //      //              } 
     556        //      //              //FINEST("Speed: %.2f %s", ms, STR(um)); 
     557        //      //      } 
     558        // 
     559        //      _optimalBw = MAP_KEY(_childPlaylists.begin()); 
     560        // 
     561        //      FOR_MAP(_childPlaylists, uint32_t, Playlist *, i) { 
     562        //              uint32_t testBandwidth = MAP_KEY(i); 
     563        //              //FINEST("meanSpeed: %.2f; testBandwidth: %.2f", meanSpeed, testBandwidth); 
     564        //              if (meanSpeed > testBandwidth) { 
     565        //                      _optimalBw = testBandwidth; 
    545566        //              } 
    546         //              //FINEST("Speed: %.2f %s", ms, STR(um)); 
    547567        //      } 
    548  
    549         _optimalBw = MAP_KEY(_childPlaylists.begin()); 
    550  
    551         FOR_MAP(_childPlaylists, uint32_t, Playlist *, i) { 
    552                 uint32_t testBandwidth = MAP_KEY(i); 
    553                 //FINEST("meanSpeed: %.2f; testBandwidth: %.2f", meanSpeed, testBandwidth); 
    554                 if (meanSpeed > testBandwidth) { 
    555                         _optimalBw = testBandwidth; 
    556                 } 
    557         } 
    558         if (before != _optimalBw) { 
    559                 if (before < _optimalBw) { 
    560                         if (GETAVAILABLEBYTESCOUNT(_avData) < _maxAVBufferSize / 3) { 
    561                                 _optimalBw = before; 
    562                         } else { 
    563                                 INFO("BW changed: before: %d; after: %d; speed: %.3f", 
    564                                                 before, _optimalBw, meanSpeed); 
    565                         } 
    566                 } else { 
    567                         INFO("BW changed: before: %d; after: %d; speed: %.3f", 
    568                                         before, _optimalBw, meanSpeed); 
    569                 } 
    570         } 
     568        //      if (before != _optimalBw) { 
     569        //              if (before < _optimalBw) { 
     570        //                      if (GETAVAILABLEBYTESCOUNT(_avData) < _maxAVBufferSize / 3) { 
     571        //                              _optimalBw = before; 
     572        //                      } else { 
     573        //                              INFO("BW changed: before: %d; after: %d; speed: %.3f", 
     574        //                                              before, _optimalBw, meanSpeed); 
     575        //                      } 
     576        //              } else { 
     577        //                      INFO("BW changed: before: %d; after: %d; speed: %.3f", 
     578        //                                      before, _optimalBw, meanSpeed); 
     579        //              } 
     580        //      } 
    571581 
    572582        return true; 
  • trunk/sources/applications/applestreamingclient/src/protocols/variant/variantappprotocolhandler.cpp

    r80 r102  
    7070        } else if (type == ASC_REQ_TYPE_COMMAND_PLAY) { 
    7171                ProcessCommandPlay(pProtocol, lastReceived); 
     72        } else if (type == ASC_REQ_TYPE_COMMAND_SET_BITRATES) { 
     73                ProcessCommandSetBitrates(pProtocol, lastReceived); 
    7274        } else if (type == ASC_REQ_TYPE_COMMAND_PAUSE) { 
    7375                ProcessCommandPause(pProtocol, lastReceived); 
     
    116118                BaseVariantProtocol *pProtocol, Variant &request) { 
    117119        ((AppleStreamingClientApplication *) GetApplication())->CloseAllContexts(); 
     120        ASC_RES_BUILD_OK(request, Variant()); 
     121} 
     122 
     123void VariantAppProtocolHandler::ProcessCommandSetBitrates( 
     124                BaseVariantProtocol *pProtocol, Variant &request) { 
     125        GET_CONTEXT(pProtocol, request); 
     126        map<uint32_t, uint32_t> bws; 
     127 
     128        FOR_MAP(ASC_REQ_COMMAND_SET_BITRATES_BWS(request), string, Variant, i) { 
     129                FINEST("(uint32_t)MAP_VAL(i): %d", (uint32_t) MAP_VAL(i)); 
     130                bws[(uint32_t) MAP_VAL(i)] = (uint32_t) MAP_VAL(i); 
     131        } 
     132        pContext->SetAllowedBitrates(bws); 
    118133        ASC_RES_BUILD_OK(request, Variant()); 
    119134} 
  • trunk/sources/thelib/src/protocols/rtp/connectivity/outboundconnectivity.cpp

    r96 r102  
    423423 
    424424        //6. RTP 
    425         FINEST("rate: %d", rate); 
     425        //FINEST("rate: %d", rate); 
    426426        double rtpDouble = ((currentTime - _startupTime) / (double) CLOCKS_PER_SEC) * rate; 
    427         FINEST("rtpDouble: %.2f", rtpDouble); 
     427        //FINEST("rtpDouble: %.2f", rtpDouble); 
    428428        uint32_t rtp = (uint32_t) rtpDouble; 
    429         FINEST("rtp: %d", rtp); 
     429        //FINEST("rtp: %d", rtp); 
     430        //uint32_t packetRtp = ntohlp(pSrc + 4); 
     431        //FINEST("packetRtp: %d", packetRtp); 
     432        //FINEST("diff: %.0f", (double) packetRtp - (double) rtp); 
    430433        put_htonl(pDest + 16, rtp); 
    431434        //memcpy(pDest + 16, pSrc + 4, 4); 
Note: See TracChangeset for help on using the changeset viewer.