Commit 462cdc3a8e5c4b30c75fc64efeaa8522ea1ee5dd

Authored by Wesnydy Ribeiro
1 parent e50b26ec
Exists in release

Documentation of Mixer.py

Showing 1 changed file with 58 additions and 4 deletions   Show diff stats
core/mixer.py
1   -#!/usr/bin/python
  1 +#!/usr/bin/env python
2 2 # -*- coding: utf-8 -*-
3 3  
4 4 """
... ... @@ -19,11 +19,12 @@ import os
19 19 import pika
20 20 import json
21 21 import PikaManager
  22 +import logging #Logging
  23 +
22 24 from subprocess import call, Popen, PIPE
23 25 from thread import start_new_thread
24 26 from time import sleep
25 27 from urllib import urlretrieve
26   -import logging #Logging
27 28  
28 29 PATH_VIDEO="/home/caiomcg/videos/"
29 30  
... ... @@ -49,6 +50,19 @@ logger.addHandler(ch)
49 50 manager = PikaManager.PikaManager('150.165.205.10', "test", "test")
50 51  
51 52 def main_video_height(main_video):
  53 + """
  54 + Extract height information of video.
  55 +
  56 + Parameters
  57 + ----------
  58 + main_video : string
  59 + Video to obtain height.
  60 +
  61 + Returns
  62 + -------
  63 + string
  64 + None if failed to extract info. The height if extraction has been successfuly.
  65 + """
52 66 logger.info("Extraindo informações de resolução do vídeo original")
53 67 try:
54 68 # Obtains the main video height using ffprobe
... ... @@ -66,6 +80,21 @@ def main_video_height(main_video):
66 80 return None
67 81  
68 82 def secondary_video_heigth(main_height, window_size):
  83 + """
  84 + Calculates the height of window.
  85 +
  86 + Parameters
  87 + ----------
  88 + main_height : string
  89 + Height of main video.
  90 + window_size : string
  91 + User choice of size of window.
  92 +
  93 + Returns
  94 + -------
  95 + number
  96 + The height of window.
  97 + """
69 98 logger.info("Calculando a resolução da janela de libras")
70 99 # Set the default height of main video if a height is not given
71 100 if main_height is None:
... ... @@ -81,6 +110,19 @@ def secondary_video_heigth(main_height, window_size):
81 110 return int(0.4 * int(main_height))
82 111  
83 112 def secondary_video_position(window_position):
  113 + """
  114 + Defines the position of window.
  115 +
  116 + Parameters
  117 + ----------
  118 + window_position : string
  119 + User choice of position of window.
  120 +
  121 + Returns
  122 + -------
  123 + string
  124 + The configurations of position of window.
  125 + """
84 126 logger.info("Definindo a posição da janela de libras")
85 127 # Overlap the window at top Left on main video
86 128 if window_position == 'top_left':
... ... @@ -96,6 +138,20 @@ def secondary_video_position(window_position):
96 138 return "main_w-overlay_w-10:main_h-overlay_h-10"
97 139  
98 140 def run(ch, method, properties, body):
  141 + """
  142 + Execute the worker.
  143 +
  144 + Parameters
  145 + ----------
  146 + ch : object
  147 + Channel of communication.
  148 + method : function
  149 + Callback.
  150 + properties : object
  151 + Message containing a set of 14 properties.
  152 + body : json object
  153 + Informations received from queue.
  154 + """
99 155 logger.info("Processando a requisição " + properties.correlation_id.encode("utf-8"))
100 156 # body it's a json that contains main video, libras video, window size and window position
101 157 body = json.loads(body)
... ... @@ -146,9 +202,7 @@ def run(ch, method, properties, body):
146 202 os.remove(body["libras_video"])
147 203 # Send the body to the queue
148 204 logger.info("Enviando para a fila de videos")
149   - print("Sending to queue")
150 205 manager.send_to_queue("videos", body, properties)
151   - print("Sent")
152 206  
153 207 # Starts listening
154 208 print("Mixer listening...")
... ...