src/pyams_media/interfaces/__init__.py
changeset 0 fd39db613f8b
child 1 1ade73c9f2c0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_media/interfaces/__init__.py	Wed Sep 02 15:31:55 2015 +0200
@@ -0,0 +1,198 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+from collections import OrderedDict
+
+# import interfaces
+
+# import packages
+from zope.interface import Interface, Attribute
+from zope.schema import List, Choice, Int
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+
+from pyams_media import _
+
+
+#
+# Medias interfaces
+#
+
+CONVERTER_NAME = 'Medias converter'
+CONVERTER_HANDLER_KEY = 'pyams_media.tcp_handler'
+
+CUSTOM_AUDIO_TYPES = (b'application/ogg',)
+CUSTOM_VIDEO_TYPES = ()
+
+
+class IMediaInfo(Interface):
+    """Media file info interface"""
+
+    infos = Attribute("Complete media info dictionary")
+
+
+#
+# Media converter utility interfaces
+#
+
+class IMediaConverter(Interface):
+    """Media converter interface"""
+
+    label = Attribute("Media converter label")
+
+    format = Attribute("Media converter target format")
+
+    def convert(self, media):
+        """Convert media to format handled by given converter"""
+
+
+class IMediaVideoConverter(IMediaConverter):
+    """Media video converter"""
+
+
+class IMediaAudioConverter(IMediaConverter):
+    """Media audio converter"""
+
+
+#
+# Media conversions adapter interfaces
+#
+
+class IMediaConversions(Interface):
+    """Media conversions interface"""
+
+    def add_conversion(self, conversion, format, extension=None, width=None):
+        """Add given conversion to media"""
+
+    def has_conversion(self, formats):
+        """Check if one of given formats is available in conversions"""
+
+    def get_conversion(self, format):
+        """Get converted media for given format and width"""
+
+    def get_conversions(self):
+        """Get current list of media conversions"""
+
+
+class IMediaConversion(Interface):
+    """Marker interface for already converted media files"""
+
+
+#
+# Media conversion utility configuration interface
+#
+
+VIDEO_FRAME_SIZE = {'sqcif': (128, 96),
+                    'qqvga': (160, 120),
+                    'qcif': (176, 144),
+                    'cga': (320, 200),
+                    'qvga': (320, 240),
+                    'cif': (352, 288),
+                    'vga': (640, 480),
+                    '4cif': (704, 576),
+                    'svga': (800, 600),
+                    'wvga': (852, 480),
+                    'hd480': (852, 480),
+                    'hd720': (1280, 720),
+                    'xga': (1024, 768),
+                    'sxga': (1280, 1024),
+                    'wxga': (1366, 768),
+                    'uxga': (1600, 1200),
+                    'wsxga': (1600, 1024),
+                    'hd1080': (1920, 1080),
+                    'wuxga': (1920, 1200),
+                    'qxga': (2048, 1536),
+                    'wqxga': (2560, 1600),
+                    'qsxga': (2560, 2048),
+                    'wqsxga': (3200, 2048),
+                    'wquxga': (3840, 2400),
+                    'hsxga': (5120, 4096),
+                    'whsxga': (6400, 4096),
+                    'whuxga': (7680, 4800)}
+
+
+VIDEO_FRAME_SIZE_NAMES = OrderedDict((('sqcif', "sqcif (128x96)"),
+                                      ('qqvga', "qqvga (160x120)"),
+                                      ('qcif', "qcif (176x144)"),
+                                      ('cga', "cga (320x200)"),
+                                      ('qvga', "qvga (320x240)"),
+                                      ('cif', "cif (352x288)"),
+                                      ('vga', "vga (640x480)"),
+                                      ('4cif', "4cif (704x576)"),
+                                      ('svga', "svga (800x600)"),
+                                      ('wvga', "wvga (852x480)"),
+                                      ('hd480', "hd480 (852x480)"),
+                                      ('hd720', "hd720 (1280x720)"),
+                                      ('xga', "xga (1024x768)"),
+                                      ('sxga', "sxga (1280x1024)"),
+                                      ('wxga', "wxga (1366x768)"),
+                                      ('uxga', "uxga (1600x1200)"),
+                                      ('wsxga', "wsxga (1600x1024)"),
+                                      ('hd1080', "hd1080 (1920x1080)"),
+                                      ('wuxga', "wuxga (1920x1200)"),
+                                      ('qxga', "qxga (2048x1536)"),
+                                      ('wqxga', "wqxga (2560x1600)"),
+                                      ('qsxga', "qsxga (2560x2048)"),
+                                      ('wqsxga', "wqsxga (3200x2048)"),
+                                      ('wquxga', "wquxga (3840x2400)"),
+                                      ('hsxga', "hsxga (5120x4096)"),
+                                      ('whsxga', "whsxga (6400x4096)"),
+                                      ('whuxga', "whuxga (7680x4800)")))
+
+
+VIDEO_FRAME_SIZE_VOCABULARY = SimpleVocabulary([SimpleTerm(v, title=t) for v, t in VIDEO_FRAME_SIZE_NAMES.items()])
+
+
+class IMediaConversionUtility(Interface):
+    """Media conversion client interface"""
+
+    zeo_connection = Choice(title=_("ZEO connection name"),
+                            description=_("Name of ZEO connection utility defining converter connection"),
+                            required=False,
+                            vocabulary="PyAMS ZEO connections")
+
+    video_formats = List(title=_("Video formats conversions"),
+                         description=_("Published video files will be automatically converted to this format"),
+                         value_type=Choice(vocabulary="PyAMS media video converters"),
+                         required=False)
+
+    video_frame_size = List(title=_("Video frames size"),
+                            description=_("Leave empty to keep original frame size..."),
+                            required=True,
+                            value_type=Choice(vocabulary=VIDEO_FRAME_SIZE_VOCABULARY))
+
+    video_audio_sampling = Int(title=_("Video audio frequency"),
+                               description=_("A common value is 22050. Leave empty to keep original value."),
+                               required=False)
+
+    video_audio_bitrate = Int(title=_("Video audio bitrate"),
+                              description=_("In kilo-bytes per second. Leave empty to keep original value."),
+                              required=False)
+
+    video_quantisation = Int(title=_("Video quantisation scale"),
+                             description=_("Lower value indicates higher quality"),
+                             required=False,
+                             default=1)
+
+    audio_formats = List(title=_("Audio formats conversions"),
+                         description=_("Published audio files will be automatically converted to this format"),
+                         value_type=Choice(vocabulary="PyAMS media audio converters"),
+                         required=False)
+
+    def check_media_conversion(self, media):
+        """Check if conversion is needed for given media"""
+
+    def convert(self, media, format):
+        """Convert given media to requested format"""