Sciter: F:/hsmile5/sdk/include/behaviors/behavior_camera_capture.cpp Source File

Sciter  3.3.2.5
Sciter API
behavior_camera_capture.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "sciter-x-dom.hpp"
3 #include "sciter-x-behavior.h"
4 
5 #if TRUE // change it to FALSE to disable camera functionality
6 
7 #include "camera/camera-capture.h"
8 #include "camera/camera-capture.cpp"
9 
10 namespace sciter
11 {
12 /*
13 
14 BEHAVIOR: camera_stream
15  provides video frames from camera
16 COMMENTS:
17  <video style="behavior:camera video" />
18 SAMPLE:
19  See: samples/video/video-camera-behavior.htm
20 */
21 
22 struct camera_stream: public event_handler
23 {
24  com::ptr<camera::capture> pcapt;
25  aux::asset_ptr<sciter::video_destination> rendering_site;
26  // ctor
27  camera_stream() {}
28  virtual ~camera_stream() {}
29 
30  virtual bool subscription( HELEMENT he, UINT& event_groups )
31  {
32  event_groups = HANDLE_BEHAVIOR_EVENT; // we only handle VIDEO_BIND_RQ here
33  return true;
34  }
35 
36  virtual void attached (HELEMENT he ) { }
37 
38  virtual void detached (HELEMENT he ) { delete this; }
39  virtual bool on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT_PTR reason )
40  {
41  if(type != VIDEO_BIND_RQ)
42  return false;
43  // we handle only VIDEO_BIND_RQ requests here
44 
45  if( !reason )
46  return true; // first phase, consume the event to mark as we will provide frames
47 
48  rendering_site = (sciter::video_destination*) reason;
49  return true;
50  }
51 
52  sciter::value get_devices() {
53  camera::device_list devices;
54  devices.enumerate_devices();
55  sciter::value r;
56  for( unsigned n = 0; n < devices.count(); ++n ) {
57  sciter::string name;
58  if(devices.get_device_name(n,name))
59  r.append( sciter::value(name) );
60  }
61  return r;
62  }
63 
64  sciter::value stream_from( const sciter::value& device ) // either int (index) or string (name)
65  {
66  if(pcapt)
67  pcapt->end_capture();
68  pcapt = camera::capture::create_instance(rendering_site,device);
69  return sciter::value(true);
70  }
71 
72  // scripting methods
73  BEGIN_FUNCTION_MAP
74  FUNCTION_0("devices",get_devices) // devices() : (array of strings), get list of names of devices
75  FUNCTION_1("streamFrom",stream_from) // streamFrom(indexOrName: int | string), start streaming from the camera
76  END_FUNCTION_MAP
77 
78 };
79 
80 struct camera_stream_factory: public behavior_factory {
81 
82  camera_stream_factory(): behavior_factory("camera") {}
83 
84  // the only behavior_factory method:
85  virtual event_handler* create(HELEMENT he) { return new camera_stream(); }
86 
87 };
88 
89 // instantiating and attaching it to the global list
90 camera_stream_factory camera_stream_factory_instance;
91 
92 
93 }
94 
95 #endif
Behaiviors support (a.k.a windowless scriptable controls)
static capture * create_instance(sciter::video_destination *pdst, const sciter::value &source_name_or_index)
BEHAVIOR_EVENTS
void append(const value &v)
Definition: value.hpp:332
unsigned count() const
Definition: camera-capture.h:56
bool get_device_name(unsigned index, sciter::string &name)
void * HELEMENT
Definition: sciter-x-dom.h:40
std::basic_string< WCHAR > string
Definition: value.hpp:42

AltStyle によって変換されたページ (->オリジナル) /