Home | History | Annotate | Download | only in test
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "webrtc/modules/video_coding/main/test/video_source.h"
     12 
     13 #include <assert.h>
     14 
     15 #include "webrtc/test/testsupport/fileutils.h"
     16 
     17 VideoSource::VideoSource()
     18 :
     19 _fileName(webrtc::test::ProjectRootPath() + "resources/foreman_cif.yuv"),
     20 _width(352),
     21 _height(288),
     22 _type(webrtc::kI420),
     23 _frameRate(30)
     24 {
     25    //
     26 }
     27 
     28 VideoSource::VideoSource(std::string fileName, VideoSize size,
     29     float frameRate, webrtc::VideoType type /*= webrtc::kI420*/)
     30 :
     31 _fileName(fileName),
     32 _width(0),
     33 _height(0),
     34 _type(type),
     35 _frameRate(frameRate)
     36 {
     37     assert(size != kUndefined && size != kNumberOfVideoSizes);
     38     assert(type != webrtc::kUnknown);
     39     assert(frameRate > 0);
     40     GetWidthHeight(size);
     41 }
     42 
     43 VideoSource::VideoSource(std::string fileName, uint16_t width, uint16_t height,
     44     float frameRate /*= 30*/, webrtc::VideoType type /*= webrtc::kI420*/)
     45 :
     46 _fileName(fileName),
     47 _width(width),
     48 _height(height),
     49 _type(type),
     50 _frameRate(frameRate)
     51 {
     52     assert(width > 0);
     53     assert(height > 0);
     54     assert(type != webrtc::kUnknown);
     55     assert(frameRate > 0);
     56 }
     57 
     58 int32_t
     59 VideoSource::GetFrameLength() const
     60 {
     61     return webrtc::CalcBufferSize(_type, _width, _height);
     62 }
     63 
     64 std::string
     65 VideoSource::GetName() const
     66 {
     67     // Remove path.
     68     size_t slashPos = _fileName.find_last_of("/\\");
     69     if (slashPos == std::string::npos)
     70     {
     71         slashPos = 0;
     72     }
     73     else
     74     {
     75         slashPos++;
     76     }
     77 
     78     // Remove extension and underscored suffix if it exists.
     79     //return _fileName.substr(slashPos, std::min(_fileName.find_last_of("_"),
     80     //    _fileName.find_last_of(".")) - slashPos);
     81     // MS: Removing suffix, not underscore....keeping full file name
     82     return _fileName.substr(slashPos, _fileName.find_last_of(".") - slashPos);
     83 
     84 }
     85 
     86 int
     87 VideoSource::GetWidthHeight( VideoSize size)
     88 {
     89     switch(size)
     90     {
     91     case kSQCIF:
     92         _width = 128;
     93         _height = 96;
     94         return 0;
     95     case kQQVGA:
     96         _width = 160;
     97         _height = 120;
     98         return 0;
     99     case kQCIF:
    100         _width = 176;
    101         _height = 144;
    102         return 0;
    103     case kCGA:
    104         _width = 320;
    105         _height = 200;
    106         return 0;
    107     case kQVGA:
    108         _width = 320;
    109         _height = 240;
    110         return 0;
    111     case kSIF:
    112         _width = 352;
    113         _height = 240;
    114         return 0;
    115     case kWQVGA:
    116         _width = 400;
    117         _height = 240;
    118         return 0;
    119     case kCIF:
    120         _width = 352;
    121         _height = 288;
    122         return 0;
    123     case kW288p:
    124         _width = 512;
    125         _height = 288;
    126         return 0;
    127     case k448p:
    128         _width = 576;
    129         _height = 448;
    130         return 0;
    131     case kVGA:
    132         _width = 640;
    133         _height = 480;
    134         return 0;
    135     case k432p:
    136         _width = 720;
    137         _height = 432;
    138         return 0;
    139     case kW432p:
    140         _width = 768;
    141         _height = 432;
    142         return 0;
    143     case k4SIF:
    144         _width = 704;
    145         _height = 480;
    146         return 0;
    147     case kW448p:
    148         _width = 768;
    149         _height = 448;
    150         return 0;
    151     case kNTSC:
    152         _width = 720;
    153         _height = 480;
    154         return 0;
    155     case kFW448p:
    156         _width = 800;
    157         _height = 448;
    158         return 0;
    159     case kWVGA:
    160         _width = 800;
    161         _height = 480;
    162         return 0;
    163     case k4CIF:
    164         _width = 704;
    165         _height = 576;
    166         return 0;
    167     case kSVGA:
    168         _width = 800;
    169         _height = 600;
    170         return 0;
    171     case kW544p:
    172         _width = 960;
    173         _height = 544;
    174         return 0;
    175     case kW576p:
    176         _width = 1024;
    177         _height = 576;
    178         return 0;
    179     case kHD:
    180         _width = 960;
    181         _height = 720;
    182         return 0;
    183     case kXGA:
    184         _width = 1024;
    185         _height = 768;
    186         return 0;
    187     case kFullHD:
    188         _width = 1440;
    189         _height = 1080;
    190         return 0;
    191     case kWHD:
    192         _width = 1280;
    193         _height = 720;
    194         return 0;
    195     case kWFullHD:
    196         _width = 1920;
    197         _height = 1080;
    198         return 0;
    199     default:
    200         return -1;
    201     }
    202 }
    203