Add timestamp to m3u filename. Change print fmt.

This commit is contained in:
Taeho Oh 2016-02-22 23:23:41 +09:00
parent 65477c5009
commit 32b602aad3

View File

@ -444,7 +444,8 @@ static gint _omvs_wait_for_multicast_packet(void) {
gint64 time1, time2;
OMVSGst gst;
gchar *cur_uri;
gchar *cur_filename;
gchar *cur_addr_str;
gint udp_port;
pcap = pcap_open_live(_omvs_net_dev_names[_omvs_net_dev_idx],
sizeof(OMVSEthHdr) + sizeof(OMVSIPHdr) + sizeof(OMVSUDPHdr),
@ -460,6 +461,8 @@ static gint _omvs_wait_for_multicast_packet(void) {
}
gst = NULL;
cur_uri = NULL;
cur_addr_str = NULL;
urihashtable =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
time1 = g_get_monotonic_time();
@ -470,7 +473,6 @@ static gint _omvs_wait_for_multicast_packet(void) {
OMVSIPHdr *ip;
OMVSUDPHdr *udp;
guint ip_hdr_len;
gint udp_port;
GInetAddress *addr;
gchar *addr_str;
guint32 haddr;
@ -485,30 +487,17 @@ static gint _omvs_wait_for_multicast_packet(void) {
if (gst) {
time2 = g_get_monotonic_time();
if (omvs_gst_is_finished(gst)) {
if (omvs_gst_is_finished(gst) ||
time2 - time1 > (gint64)((gint64)_omvs_timeout * 1000)) {
if (!_omvs_quiet) {
g_print("[%p] finish scanning %s\n", (void *)g_thread_self(),
cur_uri);
cur_addr_str);
}
omvs_gst_close(gst);
gst = NULL;
if (g_access(cur_filename, F_OK) == 0) {
_omvs_m3u_idx++;
g_mutex_lock(&_omvs_mutex);
fprintf(_omvs_m3u_fp, "#EXTINF:%u,%u\n", _omvs_m3u_idx,
_omvs_m3u_idx);
fprintf(_omvs_m3u_fp, "%s\n", cur_uri);
fflush(_omvs_m3u_fp);
g_mutex_unlock(&_omvs_mutex);
}
} else if (time2 - time1 > (gint64)((gint64)_omvs_timeout * 1000)) {
if (!_omvs_quiet) {
g_print("[%p] finish scanning %s\n", (void *)g_thread_self(),
cur_uri);
}
omvs_gst_close(gst);
gst = NULL;
if (g_access(cur_filename, F_OK) == 0) {
filename = g_strdup_printf("%s/%s-%d.png", _omvs_outdir, cur_addr_str,
udp_port);
if (g_access(filename, F_OK) == 0) {
_omvs_m3u_idx++;
g_mutex_lock(&_omvs_mutex);
fprintf(_omvs_m3u_fp, "#EXTINF:%u,%u\n", _omvs_m3u_idx,
@ -517,6 +506,11 @@ static gint _omvs_wait_for_multicast_packet(void) {
fflush(_omvs_m3u_fp);
g_mutex_unlock(&_omvs_mutex);
}
g_free(filename);
g_free(cur_uri);
g_free(cur_addr_str);
cur_uri = NULL;
cur_addr_str = NULL;
} else {
continue;
}
@ -573,24 +567,27 @@ static gint _omvs_wait_for_multicast_packet(void) {
(haddr >> 8) & 0xff,
(haddr >> 0) & 0xff);
uri = g_strdup_printf("rtp://%s:%u", addr_str, udp_port);
filename =
g_strdup_printf("%s/%s-%d.png", _omvs_outdir, addr_str, udp_port);
g_free(addr_str);
if (!g_hash_table_insert(urihashtable, uri, filename)) {
if (!g_hash_table_replace(urihashtable, uri, addr_str)) {
continue;
}
cur_uri = uri;
cur_filename = filename;
g_assert(cur_uri == NULL);
cur_uri = g_strdup(uri);
g_assert(cur_addr_str == NULL);
cur_addr_str = g_strdup(addr_str);
filename =
g_strdup_printf("%s/%s-%d.png", _omvs_outdir, cur_addr_str, udp_port);
if (!_omvs_quiet) {
g_print("[%p] start scanning %s\n", (void *)g_thread_self(), cur_uri);
g_print("[%p] start scanning %s\n", (void *)g_thread_self(),
cur_addr_str);
g_print("[%p] trying to save %s to %s\n", (void *)g_thread_self(),
cur_uri, cur_filename);
cur_uri, filename);
}
time1 = g_get_monotonic_time();
g_assert(gst == NULL);
gst = omvs_gst_open(cur_uri, cur_filename);
gst = omvs_gst_open(cur_uri, filename);
g_free(filename);
}
g_hash_table_destroy(urihashtable);
@ -612,6 +609,7 @@ int main(int argc, char *argv[]) {
gint idx_ipaddr;
OMVSScanner omvs_scanner;
gchar *m3u_path;
gint64 time;
if (_omvs_init_net_devs_info() != 0) {
ret = -1;
@ -652,8 +650,10 @@ int main(int argc, char *argv[]) {
omvs_gst_plugin_register();
g_mkdir(_omvs_outdir, 0755);
m3u_path = g_strdup_printf("%s/omvs.m3u", _omvs_outdir);
_omvs_m3u_fp = fopen(m3u_path, "a");
time = g_get_monotonic_time();
m3u_path = g_strdup_printf("%s/omvs_%" G_GUINT64_FORMAT ".m3u", _omvs_outdir,
time);
_omvs_m3u_fp = fopen(m3u_path, "w");
if (_omvs_m3u_fp == NULL) {
g_print("can't create %s", m3u_path);
g_free(m3u_path);