Ejemplo n.º 1
0
 public static PresetWatermarkUnmarshaller GetInstance()
 {
     if (instance == null)
     {
         instance = new PresetWatermarkUnmarshaller();
     }
     return(instance);
 }
Ejemplo n.º 2
0
        public VideoParameters Unmarshall(JsonUnmarshallerContext context)
        {
            if (context.CurrentTokenType == JsonUnmarshallerContext.TokenType.Null)
            {
                return(null);
            }
            VideoParameters videoParameters = new VideoParameters();

            videoParameters.CodecOptions = null;
            videoParameters.Watermarks   = null;

            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if ((context.IsKey) && (context.CurrentDepth == targetDepth))
                {
                    context.Read();
                    context.Read();

                    if (context.TestExpression("Codec", targetDepth))
                    {
                        videoParameters.Codec = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("CodecOptions", targetDepth))
                    {
                        videoParameters.CodecOptions = new Dictionary <String, String>();
                        KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.GetInstance(), StringUnmarshaller.GetInstance());
                        while (context.Read())
                        {
                            if (((context.IsStartArray || context.IsStartElement || context.IsLeafValue) && (context.CurrentDepth == targetDepth)) ||
                                ((context.IsKey) && (context.CurrentDepth == targetDepth + 1)))
                            {
                                KeyValuePair <string, string> kvp = unmarshaller.Unmarshall(context);
                                videoParameters.CodecOptions.Add(kvp.Key, kvp.Value);
                            }
                            else if (context.IsEndElement)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("KeyframesMaxDist", targetDepth))
                    {
                        videoParameters.KeyframesMaxDist = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("FixedGOP", targetDepth))
                    {
                        videoParameters.FixedGOP = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("BitRate", targetDepth))
                    {
                        videoParameters.BitRate = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("FrameRate", targetDepth))
                    {
                        videoParameters.FrameRate = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("MaxFrameRate", targetDepth))
                    {
                        videoParameters.MaxFrameRate = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("Resolution", targetDepth))
                    {
                        videoParameters.Resolution = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("AspectRatio", targetDepth))
                    {
                        videoParameters.AspectRatio = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("MaxWidth", targetDepth))
                    {
                        videoParameters.MaxWidth = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("MaxHeight", targetDepth))
                    {
                        videoParameters.MaxHeight = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("DisplayAspectRatio", targetDepth))
                    {
                        videoParameters.DisplayAspectRatio = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("SizingPolicy", targetDepth))
                    {
                        videoParameters.SizingPolicy = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("PaddingPolicy", targetDepth))
                    {
                        videoParameters.PaddingPolicy = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("Watermarks", targetDepth))
                    {
                        videoParameters.Watermarks = new List <PresetWatermark>();
                        PresetWatermarkUnmarshaller unmarshaller = PresetWatermarkUnmarshaller.GetInstance();
                        while (context.Read())
                        {
                            if ((context.IsArrayElement) && (context.CurrentDepth == targetDepth))
                            {
                                videoParameters.Watermarks.Add(unmarshaller.Unmarshall(context));
                            }
                            else if (context.IsEndArray)
                            {
                                break;
                            }
                        }
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth <= originalDepth)
                {
                    return(videoParameters);
                }
            }


            return(videoParameters);
        }
Ejemplo n.º 3
0
        public VideoParameters Unmarshall(JsonUnmarshallerContext context)
        {
            context.Read();
            if (context.CurrentTokenType == JsonToken.Null)
            {
                return(null);
            }
            VideoParameters videoParameters = new VideoParameters();


            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Codec", targetDepth))
                {
                    videoParameters.Codec = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("CodecOptions", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <String, String, StringUnmarshaller, StringUnmarshaller>(
                        StringUnmarshaller.GetInstance(), StringUnmarshaller.GetInstance());
                    videoParameters.CodecOptions = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("KeyframesMaxDist", targetDepth))
                {
                    videoParameters.KeyframesMaxDist = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("FixedGOP", targetDepth))
                {
                    videoParameters.FixedGOP = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("BitRate", targetDepth))
                {
                    videoParameters.BitRate = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("FrameRate", targetDepth))
                {
                    videoParameters.FrameRate = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("MaxFrameRate", targetDepth))
                {
                    videoParameters.MaxFrameRate = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Resolution", targetDepth))
                {
                    videoParameters.Resolution = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("AspectRatio", targetDepth))
                {
                    videoParameters.AspectRatio = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("MaxWidth", targetDepth))
                {
                    videoParameters.MaxWidth = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("MaxHeight", targetDepth))
                {
                    videoParameters.MaxHeight = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("DisplayAspectRatio", targetDepth))
                {
                    videoParameters.DisplayAspectRatio = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("SizingPolicy", targetDepth))
                {
                    videoParameters.SizingPolicy = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("PaddingPolicy", targetDepth))
                {
                    videoParameters.PaddingPolicy = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Watermarks", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <PresetWatermark, PresetWatermarkUnmarshaller>(
                        PresetWatermarkUnmarshaller.GetInstance());
                    videoParameters.Watermarks = unmarshaller.Unmarshall(context);

                    continue;
                }
            }

            return(videoParameters);
        }