Skip to content

Commit d346ea6

Browse files
Updated Local Capture Device plug-in, so it can use JPEG encoding if camera supports it.
1 parent 3ad00d1 commit d346ea6

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

sources/plugins/video_sources/vs_dshow/DirectShowVideoSourcePlugin.cpp

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
DirectShow video source plug-ins of Computer Vision Sandbox
33
4-
Copyright (C) 2011-2019, cvsandbox
4+
Copyright (C) 2011-2020, cvsandbox
55
http://www.cvsandbox.com/contacts.html
66
77
This program is free software; you can redistribute it and/or modify
@@ -23,6 +23,7 @@
2323
#include <string.h>
2424
#include <XVariant.hpp>
2525
#include <algorithm>
26+
#include <ximaging_formats.h>
2627

2728
using namespace std;
2829
using namespace CVSandbox;
@@ -55,12 +56,15 @@ namespace Private
5556
public:
5657
DirectShowVideoSourcePluginData( ) :
5758
UserCallbacks( { 0 } ), UserParam( 0 ),
58-
HaveCachedExposure( false ), HaveCachedExposureAuto( false )
59+
DecodedImage( nullptr ),
60+
HaveCachedExposure( false ), HaveCachedExposureAuto( false ),
61+
CachedExposure( 0 ), CachedExposureAuto( false )
5962
{
6063
}
6164

6265
~DirectShowVideoSourcePluginData( )
6366
{
67+
XImageFree( &DecodedImage );
6468
}
6569

6670
virtual void OnNewImage( const std::shared_ptr<const XImage>& image );
@@ -69,6 +73,7 @@ namespace Private
6973
public:
7074
VideoSourcePluginCallbacks UserCallbacks;
7175
void* UserParam;
76+
ximage* DecodedImage;
7277

7378
bool HaveCachedExposure;
7479
bool HaveCachedExposureAuto;
@@ -201,7 +206,7 @@ XErrorCode DirectShowVideoSourcePlugin::SetProperty( int32_t id, const xvariant*
201206
case 0:
202207
if ( xvar.Type( ) == XVT_String )
203208
{
204-
string str = xvar.ToString( &ret );
209+
string str = xvar.ToString( &ret );
205210
XDeviceName deviceName = DeviceNameFromString( str );
206211

207212
if ( !deviceName.Moniker( ).empty( ) )
@@ -509,6 +514,8 @@ XErrorCode DirectShowVideoSourcePlugin::Start( )
509514
{
510515
vector<XDevicePinInfo> inputs = mDevice->GetInputVideoPins( );
511516

517+
mDevice->PreferJpegEncoding( true );
518+
512519
if ( ( !inputs.empty( ) ) && ( mVideoInput < static_cast<uint8_t>( inputs.size( ) ) ) )
513520
{
514521
mDevice->SetVideoInput( inputs[mVideoInput] );
@@ -577,15 +584,29 @@ namespace Private
577584
// Handle new image arrived from video source
578585
void DirectShowVideoSourcePluginData::OnNewImage( const std::shared_ptr<const XImage>& image )
579586
{
580-
if ( ( UserCallbacks.NewImageCallback != 0 ) && ( image ) )
587+
if ( ( UserCallbacks.NewImageCallback != nullptr ) && ( image ) )
581588
{
582-
UserCallbacks.NewImageCallback( UserParam, image->ImageData( ) );
589+
if ( image->Format( ) != XPixelFormatJPEG )
590+
{
591+
UserCallbacks.NewImageCallback( UserParam, image->ImageData( ) );
592+
}
593+
else
594+
{
595+
if ( XDecodeJpegFromMemory( image->ImageData( )->data, image->ImageData( )->width, &DecodedImage ) == SuccessCode )
596+
{
597+
UserCallbacks.NewImageCallback( UserParam, DecodedImage );
598+
}
599+
else
600+
{
601+
OnError( "Failed decoding JPEG image" );
602+
}
603+
}
583604
}
584605
}
585606

586607
void DirectShowVideoSourcePluginData::OnError( const std::string& errorMessage )
587608
{
588-
if ( UserCallbacks.ErrorMessageCallback != 0 )
609+
if ( UserCallbacks.ErrorMessageCallback != nullptr )
589610
{
590611
UserCallbacks.ErrorMessageCallback( UserParam, errorMessage.c_str( ) );
591612
}

sources/plugins/video_sources/vs_dshow/make/mingw/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ OUT_SUB_FOLDER = cvsplugins\vs_dshow
88

99
LIBDIR = -L../../../../../../build/$(TARGET)/$(BUILD_TYPE)/lib
1010

11-
LDFLAGS += -shared
11+
LDFLAGS += -fopenmp -shared
1212

1313
include ../../../../../make/settings/mingw/build_app.mk
1414

sources/plugins/video_sources/vs_dshow/make/msvc/vs_dshow.vcxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@
106106
<WarningLevel>Level4</WarningLevel>
107107
<Optimization>Disabled</Optimization>
108108
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;VS_DSHOW_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109-
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
109+
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_imaging_formats;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
110110
<DebugInformationFormat>OldStyle</DebugInformationFormat>
111111
<MinimalRebuild>false</MinimalRebuild>
112112
</ClCompile>
113113
<Link>
114114
<SubSystem>Windows</SubSystem>
115115
<GenerateDebugInformation>true</GenerateDebugInformation>
116116
<AdditionalLibraryDirectories>..\..\..\..\..\..\build\msvc\debug\lib</AdditionalLibraryDirectories>
117-
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;iplugin.lib;%(AdditionalDependencies)</AdditionalDependencies>
117+
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;afx_imaging_formats.lib;iplugin.lib;jpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>
118118
</Link>
119119
<PostBuildEvent>
120120
<Command>xcopy /Y "$(TargetPath)" "$(ProjectDir)..\..\..\..\..\..\build\msvc\debug\bin\cvsplugins\$(ProjectName)\"
@@ -128,15 +128,15 @@ xcopy /Y "$(ProjectDir)..\..\*.txt" "$(ProjectDir)..\..\..\..\..\..\build\msvc\d
128128
<WarningLevel>Level4</WarningLevel>
129129
<Optimization>Disabled</Optimization>
130130
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;VS_DSHOW_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
131-
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
131+
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_imaging_formats;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
132132
<DebugInformationFormat>OldStyle</DebugInformationFormat>
133133
<MinimalRebuild>false</MinimalRebuild>
134134
</ClCompile>
135135
<Link>
136136
<SubSystem>Windows</SubSystem>
137137
<GenerateDebugInformation>true</GenerateDebugInformation>
138138
<AdditionalLibraryDirectories>..\..\..\..\..\..\build\msvc\debug64\lib</AdditionalLibraryDirectories>
139-
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;iplugin.lib;%(AdditionalDependencies)</AdditionalDependencies>
139+
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;afx_imaging_formats.lib;iplugin.lib;jpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>
140140
</Link>
141141
<PostBuildEvent>
142142
<Command>xcopy /Y "$(TargetPath)" "$(ProjectDir)..\..\..\..\..\..\build\msvc\debug64\bin\cvsplugins\$(ProjectName)\"
@@ -152,7 +152,7 @@ xcopy /Y "$(ProjectDir)..\..\*.txt" "$(ProjectDir)..\..\..\..\..\..\build\msvc\d
152152
<FunctionLevelLinking>true</FunctionLevelLinking>
153153
<IntrinsicFunctions>true</IntrinsicFunctions>
154154
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;VS_DSHOW_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
155-
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
155+
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_imaging_formats;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
156156
<DebugInformationFormat>OldStyle</DebugInformationFormat>
157157
</ClCompile>
158158
<Link>
@@ -161,7 +161,7 @@ xcopy /Y "$(ProjectDir)..\..\*.txt" "$(ProjectDir)..\..\..\..\..\..\build\msvc\d
161161
<EnableCOMDATFolding>true</EnableCOMDATFolding>
162162
<OptimizeReferences>true</OptimizeReferences>
163163
<AdditionalLibraryDirectories>..\..\..\..\..\..\build\msvc\release\lib</AdditionalLibraryDirectories>
164-
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;iplugin.lib;%(AdditionalDependencies)</AdditionalDependencies>
164+
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;afx_imaging_formats.lib;iplugin.lib;jpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>
165165
</Link>
166166
<PostBuildEvent>
167167
<Command>xcopy /Y "$(TargetPath)" "$(ProjectDir)..\..\..\..\..\..\build\msvc\release\bin\cvsplugins\$(ProjectName)\"
@@ -177,7 +177,7 @@ xcopy /Y "$(ProjectDir)..\..\*.txt" "$(ProjectDir)..\..\..\..\..\..\build\msvc\r
177177
<FunctionLevelLinking>true</FunctionLevelLinking>
178178
<IntrinsicFunctions>true</IntrinsicFunctions>
179179
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;VS_DSHOW_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
180-
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
180+
<AdditionalIncludeDirectories>..\..\..\..\..\afx\afx_types;..\..\..\..\..\afx\afx_types+;..\..\..\..\..\afx\afx_imaging_formats;..\..\..\..\..\afx\afx_video+;..\..\..\..\..\afx\video\afx_video_dshow+;..\..\..\..\..\core\iplugin;..\..\..\..\..\images</AdditionalIncludeDirectories>
181181
<DebugInformationFormat>OldStyle</DebugInformationFormat>
182182
</ClCompile>
183183
<Link>
@@ -186,7 +186,7 @@ xcopy /Y "$(ProjectDir)..\..\*.txt" "$(ProjectDir)..\..\..\..\..\..\build\msvc\r
186186
<EnableCOMDATFolding>true</EnableCOMDATFolding>
187187
<OptimizeReferences>true</OptimizeReferences>
188188
<AdditionalLibraryDirectories>..\..\..\..\..\..\build\msvc\release64\lib</AdditionalLibraryDirectories>
189-
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;iplugin.lib;%(AdditionalDependencies)</AdditionalDependencies>
189+
<AdditionalDependencies>afx_types.lib;afx_types+.lib;afx_video+.lib;afx_video_dshow+.lib;afx_platform+.lib;afx_imaging_formats.lib;iplugin.lib;jpeg.lib;%(AdditionalDependencies)</AdditionalDependencies>
190190
</Link>
191191
<PostBuildEvent>
192192
<Command>xcopy /Y "$(TargetPath)" "$(ProjectDir)..\..\..\..\..\..\build\msvc\release64\bin\cvsplugins\$(ProjectName)\"

sources/plugins/video_sources/vs_dshow/make/src.mk

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ SRC = vs_dshow.cpp \
1010
# additional include folders
1111
INCLUDES = -I../../../../../afx/afx_types -I../../../../../afx/afx_types+ \
1212
-I../../../../../afx/afx_video+ -I../../../../../afx/afx_platform+ \
13+
-I../../../../../afx/afx_imaging_formats \
1314
-I../../../../../afx/video/afx_video_dshow+ \
1415
-I../../../../../core/iplugin -I../../../../../images
1516

1617
# libraries to use
17-
LIBS = -liplugin -lafx_video_dshow+ -lafx_platform+ -lafx_types+ -lafx_types \
18-
-lole32 -loleaut32 -lstrmiids -luuid
18+
LIBS = -liplugin -lafx_video_dshow+ -lafx_imaging_formats -lafx_imaging \
19+
-lafx_platform+ -lafx_types+ -lafx_types \
20+
-lole32 -loleaut32 -lstrmiids -luuid -ljpeg -lexif

0 commit comments

Comments
 (0)