1/*M///////////////////////////////////////////////////////////////////////////////////////
2//
3//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4//
5//  By downloading, copying, installing or using the software you agree to this license.
6//  If you do not agree to this license, do not download, install,
7//  copy or use the software.
8//
9//
10//                           License Agreement
11//                For Open Source Computer Vision Library
12//
13// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15// Third party copyrights are property of their respective owners.
16//
17// Redistribution and use in source and binary forms, with or without modification,
18// are permitted provided that the following conditions are met:
19//
20//   * Redistribution's of source code must retain the above copyright notice,
21//     this list of conditions and the following disclaimer.
22//
23//   * Redistribution's in binary form must reproduce the above copyright notice,
24//     this list of conditions and the following disclaimer in the documentation
25//     and/or other materials provided with the distribution.
26//
27//   * The name of the copyright holders may not be used to endorse or promote products
28//     derived from this software without specific prior written permission.
29//
30// This software is provided by the copyright holders and contributors "as is" and
31// any express or implied warranties, including, but not limited to, the implied
32// warranties of merchantability and fitness for a particular purpose are disclaimed.
33// In no event shall the Intel Corporation or contributors be liable for any direct,
34// indirect, incidental, special, exemplary, or consequential damages
35// (including, but not limited to, procurement of substitute goods or services;
36// loss of use, data, or profits; or business interruption) however caused
37// and on any theory of liability, whether in contract, strict liability,
38// or tort (including negligence or otherwise) arising in any way out of
39// the use of this software, even if advised of the possibility of such damage.
40//
41//M*/
42
43#include "perf_precomp.hpp"
44#include "opencv2/highgui/highgui_c.h"
45
46using namespace std;
47using namespace testing;
48using namespace perf;
49
50#if defined(HAVE_XINE)         || \
51    defined(HAVE_GSTREAMER)    || \
52    defined(HAVE_QUICKTIME)    || \
53    defined(HAVE_QTKIT)        || \
54    defined(HAVE_AVFOUNDATION) || \
55    defined(HAVE_FFMPEG)       || \
56    defined(WIN32) /* assume that we have ffmpeg */
57
58#  define BUILD_WITH_VIDEO_INPUT_SUPPORT 1
59#else
60#  define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
61#endif
62
63DEF_PARAM_TEST_1(FileName, string);
64
65//////////////////////////////////////////////////////
66// VideoReader
67
68#if defined(HAVE_NVCUVID) && BUILD_WITH_VIDEO_INPUT_SUPPORT
69
70PERF_TEST_P(FileName, VideoReader, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"))
71{
72    declare.time(20);
73
74    const string inputFile = perf::TestBase::getDataPath(GetParam());
75
76    if (PERF_RUN_CUDA())
77    {
78        cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(inputFile);
79
80        cv::cuda::GpuMat frame;
81
82        TEST_CYCLE_N(10) d_reader->nextFrame(frame);
83
84        CUDA_SANITY_CHECK(frame);
85    }
86    else
87    {
88        cv::VideoCapture reader(inputFile);
89        ASSERT_TRUE( reader.isOpened() );
90
91        cv::Mat frame;
92
93        TEST_CYCLE_N(10) reader >> frame;
94
95        CPU_SANITY_CHECK(frame);
96    }
97}
98
99#endif
100
101//////////////////////////////////////////////////////
102// VideoWriter
103
104#if defined(HAVE_NVCUVID) && defined(WIN32)
105
106PERF_TEST_P(FileName, VideoWriter, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"))
107{
108    declare.time(30);
109
110    const string inputFile = perf::TestBase::getDataPath(GetParam());
111    const string outputFile = cv::tempfile(".avi");
112
113    const double FPS = 25.0;
114
115    cv::VideoCapture reader(inputFile);
116    ASSERT_TRUE( reader.isOpened() );
117
118    cv::Mat frame;
119
120    if (PERF_RUN_CUDA())
121    {
122        cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
123
124        cv::cuda::GpuMat d_frame;
125
126        for (int i = 0; i < 10; ++i)
127        {
128            reader >> frame;
129            ASSERT_FALSE(frame.empty());
130
131            d_frame.upload(frame);
132
133            if (d_writer.empty())
134                d_writer = cv::cudacodec::createVideoWriter(outputFile, frame.size(), FPS);
135
136            startTimer(); next();
137            d_writer->write(d_frame);
138            stopTimer();
139        }
140    }
141    else
142    {
143        cv::VideoWriter writer;
144
145        for (int i = 0; i < 10; ++i)
146        {
147            reader >> frame;
148            ASSERT_FALSE(frame.empty());
149
150            if (!writer.isOpened())
151                writer.open(outputFile, CV_FOURCC('X', 'V', 'I', 'D'), FPS, frame.size());
152
153            startTimer(); next();
154            writer.write(frame);
155            stopTimer();
156        }
157    }
158
159    SANITY_CHECK(frame);
160}
161
162#endif
163