Begin Discovery

This commit is contained in:
Florian Märkl 2019-06-12 18:41:32 +02:00
commit 98a3c74e3b
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
3 changed files with 99 additions and 2 deletions

View file

@ -21,7 +21,8 @@ set(HEADER_FILES
include/chiaki/video.h
include/chiaki/videoreceiver.h
include/chiaki/frameprocessor.h
include/chiaki/seqnum.h)
include/chiaki/seqnum.h
include/chiaki/discovery.h)
set(SOURCE_FILES
src/common.c
@ -45,7 +46,8 @@ set(SOURCE_FILES
src/audio.c
src/audioreceiver.c
src/videoreceiver.c
src/frameprocessor.c)
src/frameprocessor.c
src/discovery.c)
add_subdirectory(protobuf)
include_directories("${NANOPB_SOURCE_DIR}")

View file

@ -0,0 +1,53 @@
/*
* This file is part of Chiaki.
*
* Chiaki is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiaki is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CHIAKI_DISCOVERY_H
#define CHIAKI_DISCOVERY_H
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CHIAKI_DISCOVERY_PORT 987
#define CHIAKI_DISCOVERY_PROTOCOL_VERSION "00020020"
typedef enum chiaki_discovery_cmd_t
{
CHIAKI_DISCOVERY_CMD_SRCH
} ChiakiDiscoveryCmd;
typedef struct chiaki_discovery_packet_t
{
ChiakiDiscoveryCmd cmd;
char *protocol_version;
} ChiakiDiscoveryPacket;
typedef struct chiaki_discovery_t
{
int socket;
} ChiakiDiscovery;
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery);
CHIAKI_EXPORT void chiaki_discovery_fini(ChiakiDiscovery *discovery);
#ifdef __cplusplus
}
#endif
#endif // CHIAKI_VIDEORECEIVER_H

42
lib/src/discovery.c Normal file
View file

@ -0,0 +1,42 @@
/*
* This file is part of Chiaki.
*
* Chiaki is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Chiaki is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
*/
#include <chiaki/discovery.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
static const char *packet_srch_template =
"SRCH * HTTP/1.1\n"
"device-discovery-protocol-version:%s\n";
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery *discovery)
{
discovery->socket = socket(AF_INET, SOCK_DGRAM, 0);
if(discovery->socket < 0)
return CHIAKI_ERR_UNKNOWN;
return CHIAKI_ERR_SUCCESS;
}
CHIAKI_EXPORT void chiaki_discovery_fini(ChiakiDiscovery *discovery)
{
close(discovery->socket);
}