summaryrefslogtreecommitdiff
path: root/ipc.h
blob: 1da5ced62d124c3bcf2a2d66dae611d22ef8b171 (plain)
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
/*
 * IPC mini library
 * Copyright (C) 2014 Fluendo S.A.
 *   @author: Josep Torra <josep@fluendo.com>
 * *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __MY_IPC_H__
#define __MY_IPC_H__

#include <glib.h>
#include <glib-object.h>

#include "egl.h"

typedef enum {
  IPC_MSG_TYPE_EOS,
  IPC_MSG_TYPE_REQUEST_POOL,
  IPC_MSG_TYPE_RENDER_FRAME
} IPCMsgType;

typedef struct {
  guint32 dummy;
} IPCMsgEOS;

typedef struct {
  guint size;
  guint width;
  guint height;
} IPCMsgPoolRequest;

typedef struct {
  EGLImageMemory *mem;
} IPCMsgRenderFrame;

typedef struct {
  volatile gint refcount;

  IPCMsgType type;
  union {
    IPCMsgEOS eos;
    IPCMsgPoolRequest request_pool;
    IPCMsgRenderFrame render_frame;
  } u;
  gpointer result;

  volatile gint delivered;
  gboolean synchronous;
} IPCMessage;

typedef struct
{
  volatile gint refcount;

  GAsyncQueue *queue;
  GMutex *lock;
  GCond *cond;
} IPCChannel;

IPCMessage * ipc_message_new (IPCMsgType type);
IPCMessage * ipc_message_ref (IPCMessage * message);
IPCMessage * ipc_message_unref (IPCMessage * message);

IPCMessage * ipc_message_eos_new();

IPCMessage * ipc_message_request_pool_new (guint size, guint width, guint height);
gboolean ipc_message_request_pool_parse (IPCMessage * message, guint * size,
    guint * width, guint * height);

IPCMessage * ipc_message_render_frame_new (EGLImageMemory * mem);
gboolean ipc_message_render_frame_parse (IPCMessage * message, EGLImageMemory ** mem);

IPCChannel * ipc_channel_new ();
IPCChannel * ipc_channel_ref (IPCChannel * channel);
IPCChannel * ipc_channel_unref (IPCChannel * channel);

gpointer ipc_channel_send (IPCChannel * channel, IPCMessage * message);
IPCMessage * ipc_channel_try_pop (IPCChannel * channel);
void ipc_channel_delivered (IPCChannel * channel, IPCMessage * message,
    gpointer result);

#endif