-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcam.cc
130 lines (101 loc) · 2.74 KB
/
cam.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <Poco/ConsoleChannel.h>
#include <Poco/Exception.h>
#include <Poco/Logger.h>
#include <boost/format.hpp>
#include "cam.h"
#include "camcon.h"
#include "framempool.h"
#include "disp.h"
using Poco::ConsoleChannel;
using Poco::Logger;
using Poco::Exception;
using namespace vid;
using namespace std;
const std::string vid::Camera::get_cmd_args_format = "none";
const std::string vid::NVCamera::get_cmd_args_format =
"/cgi-bin/fwstream.cgi?" \
"FwModId=0&AppKey=0x0450f000&PortId=%d&PauseTime=0&FwCgiVer=0x0001";
std::pair<bool,StreamerSPtr>
Camera::stream(const std::string &name)
{
StreamsMap::iterator r = streams.find(name);
if (r == streams.end()) {
return make_pair(false,StreamerSPtr());
}
return make_pair(true, r->second);
}
StreamerSPtr
Camera::add_streamer(vid::Dispatcher &d, const std::string &name, const VideoMode &vmode, int id)
{
//
// 0. Get global memory pool
//
FramePool::FramePoolSPtr ppool = FramePool::global_pool();
if (!ppool) {
throw vid::exception::init_error("can't get global memory pool");
}
//
// 1. Try to connect
//
CamConnection c(url,
prepare_get_cmd(vmode, name, id),
port);
int sock = NILL_SOCKET;
try {
sock = c.connect();
} catch(Poco::Exception &e) {
Logger::get("dbg-connect").log(e);
}
if (NILL_SOCKET == sock) {
throw vid::exception::init_error("can't make a connection to device");
}
//
// 2. Create streamer object
//
JESStreamer::pointer s = JESStreamer::make_streamer( shared_from_this(),
d.service(), *ppool, sock );
// Store socket object in streamer, in not to do this
// it will be deleted with CamConnection ('c' in our case) variable.
s->store_sock_holder( c.get_so());
if (!s) { //report an error
close(sock);
throw vid::exception::init_error("failed to create streamer");
}
//
// 3. Store streamer object in local set
//
StreamsMap::iterator it = streams.find(name);
if (it != streams.end()) { // already exists, close it
it->second->close();
}
streams.insert( std::make_pair(name, s) );
//
// Finally add camera record to dispatcher
//
d.add_camera(this->idname, shared_from_this() );
return s;
}
void
Camera::del_streamer(const std::string &name)
{
StreamsMap::iterator it = streams.find(name);
if (it != streams.end()) {
it->second->close();
streams.erase(it);
}
// else: do nothing, we don't have this member
// may be throw an exception?
}
bool operator<(const vid::CameraSPtr &lhr, const vid::CameraSPtr &rhr)
{
return lhr->id_name() < rhr->id_name();
}
///
/// NVCamera methods
///
std::string
NVCamera::prepare_get_cmd(const VideoMode &, const std::string &name, int id)
{
return str(boost::format(get_cmd_args_format) % id);
}