Browse Source

MT#61977 introduce content_t

Refcounted object to contain media content

Change-Id: Idd9fe65051cf90930204bd83ee2125d1d4b79237
pull/1998/head
Richard Fuchs 4 months ago
parent
commit
d122b39313
5 changed files with 39 additions and 22 deletions
  1. +5
    -2
      recording-daemon/db.c
  2. +5
    -8
      recording-daemon/notify.c
  3. +20
    -9
      recording-daemon/output.c
  4. +1
    -1
      recording-daemon/output.h
  5. +8
    -2
      recording-daemon/types.h

+ 5
- 2
recording-daemon/db.c View File

@ -386,10 +386,11 @@ bool db_close_stream(output_t *op) {
MYSQL_BIND b[3];
bool ok = true;
content_t *content = NULL;
if ((output_storage & OUTPUT_STORAGE_DB)) {
GString *content = output_get_content(op);
content = output_get_content(op);
if (content)
stream = STR_GS(content);
stream = STR_GS(content->s);
else
ok = false;
}
@ -403,6 +404,8 @@ bool db_close_stream(output_t *op) {
execute_wrap(&stm_close_stream, b, NULL);
obj_release(content);
return ok;
}


+ 5
- 8
recording-daemon/notify.c View File

@ -23,7 +23,7 @@ struct notif_req {
// generic HTTP req
struct {
struct curl_slist *headers;
GString *content;
content_t *content;
};
// notify command
@ -127,7 +127,7 @@ static bool do_notify_http(struct notif_req *req) {
if ((ret = curl_mime_name(part, "ngfile")) != CURLE_OK)
goto fail;
if ((ret = curl_mime_data(part, req->content->str, req->content->len)) != CURLE_OK)
if ((ret = curl_mime_data(part, req->content->s->str, req->content->s->len)) != CURLE_OK)
goto fail;
if ((ret = curl_easy_setopt(c, CURLOPT_MIMEPOST, mime)) != CURLE_OK)
@ -357,16 +357,13 @@ static void notify_req_setup_http(struct notif_req *req, output_t *o, metafile_t
notify_add_header(req, "X-Recording-Tag-Metadata: %s", tag->metadata);
}
if ((output_storage & OUTPUT_STORAGE_NOTIFY)) {
req->content = output_get_content(o); // XXX refcount to avoid duplication
o->content = NULL; // take over ownership
}
if ((output_storage & OUTPUT_STORAGE_NOTIFY))
req->content = output_get_content(o);
}
static void cleanup_http(struct notif_req *req) {
curl_slist_free_all(req->headers);
if (req->content)
g_string_free(req->content, TRUE);
obj_release(req->content);
}
static const struct notif_action http_action = {


+ 20
- 9
recording-daemon/output.c View File

@ -520,9 +520,21 @@ static bool output_config(sink_t *sink, output_t *output, const format_t *reques
}
GString *output_get_content(output_t *output) {
static void content_free(content_t *s) {
g_string_free(s->s, TRUE);
}
static content_t *output_make_content(GString *s) {
content_t *ret = obj_alloc0(content_t, content_free);
ret->s = s;
return ret;
}
content_t *output_get_content(output_t *output) {
if (output->content)
return output->content;
return obj_get(output->content);
if (!output->fp)
return NULL;
@ -545,8 +557,9 @@ GString *output_get_content(output_t *output) {
return NULL;
}
output->content = content;
return content;
output->content = output_make_content(content);
return obj_get(output->content);
}
@ -567,9 +580,8 @@ static bool output_shutdown(output_t *output) {
}
else if (output->membuf) {
if (output->membuf->len) {
if (output->content)
g_string_free(output->content, TRUE);
output->content = output->membuf;
obj_release(output->content);
output->content = output_make_content(output->membuf);
output->membuf = NULL;
ret = true;
}
@ -632,8 +644,7 @@ void output_close(metafile_t *mf, output_t *output, tag_t *tag, bool discard) {
g_clear_pointer(&output->iobuf, g_free);
if (output->membuf)
g_string_free(output->membuf, TRUE);
if (output->content)
g_string_free(output->content, TRUE);
obj_release(output->content);
if (output->fp)
fclose(output->fp);
sink_close(&output->sink);


+ 1
- 1
recording-daemon/output.h View File

@ -12,7 +12,7 @@ void output_init(const char *format);
output_t *output_new_ext(metafile_t *, const char *type, const char *kind, const char *label);
void output_close(metafile_t *, output_t *, tag_t *, bool discard);
GString *output_get_content(output_t *);
content_t *output_get_content(output_t *);
void sink_init(sink_t *);


+ 8
- 2
recording-daemon/types.h View File

@ -16,6 +16,7 @@
#include "custom_poller.h"
#include "socket.h"
#include "containers.h"
#include "obj.h"
struct iphdr;
@ -35,7 +36,7 @@ typedef struct stream_s stream_t;
typedef struct ssrc_s ssrc_t;
typedef struct sink_s sink_t;
typedef struct tls_fwd_s tls_fwd_t;
typedef struct content_s content_t;
typedef void handler_func(handler_t *);
@ -212,7 +213,7 @@ struct output_s {
format_t requested_format,
actual_format;
GString *content;
content_t *content;
};
@ -222,6 +223,11 @@ struct decode_s {
sink_t tls_mix_sink;
};
struct content_s {
struct obj obj;
GString *s;
};
#endif

Loading…
Cancel
Save