cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

display-image-streams.c (2578B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include "config.h"
     21#include "display.h"
     22#include "image-stream.h"
     23#include "log.h"
     24
     25#include <guacamole/client.h>
     26
     27#include <stdlib.h>
     28
     29int guacenc_display_create_image_stream(guacenc_display* display, int index,
     30        int mask, int layer_index, const char* mimetype, int x, int y) {
     31
     32    /* Do not lookup / allocate if index is invalid */
     33    if (index < 0 || index >= GUACENC_DISPLAY_MAX_STREAMS) {
     34        guacenc_log(GUAC_LOG_WARNING, "Stream index out of bounds: %i", index);
     35        return 1;
     36    }
     37
     38    /* Free existing stream (if any) */
     39    guacenc_image_stream_free(display->image_streams[index]);
     40
     41    /* Associate new stream */
     42    guacenc_image_stream* stream = display->image_streams[index] =
     43        guacenc_image_stream_alloc(mask, layer_index, mimetype, x, y);
     44
     45    /* Return zero only if stream is not NULL */
     46    return stream == NULL;
     47
     48}
     49
     50guacenc_image_stream* guacenc_display_get_image_stream(
     51        guacenc_display* display, int index) {
     52
     53    /* Do not lookup / allocate if index is invalid */
     54    if (index < 0 || index >= GUACENC_DISPLAY_MAX_STREAMS) {
     55        guacenc_log(GUAC_LOG_WARNING, "Stream index out of bounds: %i", index);
     56        return NULL;
     57    }
     58
     59    /* Return existing stream (if any) */
     60    return display->image_streams[index];
     61
     62}
     63
     64int guacenc_display_free_image_stream(guacenc_display* display, int index) {
     65
     66    /* Do not lookup / allocate if index is invalid */
     67    if (index < 0 || index >= GUACENC_DISPLAY_MAX_STREAMS) {
     68        guacenc_log(GUAC_LOG_WARNING, "Stream index out of bounds: %i", index);
     69        return 1;
     70    }
     71
     72    /* Free stream (if allocated) */
     73    guacenc_image_stream_free(display->image_streams[index]);
     74
     75    /* Mark stream as freed */
     76    display->image_streams[index] = NULL;
     77
     78    return 0;
     79
     80}
     81