Ejemplo n.º 1
0
        public VideoFile Convert(string filename, string format)
        {
            var file = new VideoFile(filename);

            var sourceCodec = new CodecFactory().Extract(file);

            ICodec destinationCodec;

            if (format == "mp4")
            {
                destinationCodec = new Mpeg4CompressionCodec();
            }
            else
            {
                destinationCodec = new OggCompressionCodec();
            }

            var buffer = BitrateReader.Read(filename, sourceCodec);

            var result = BitrateReader.Convert(buffer, destinationCodec);

            result = new AudioMixer().Fix(result);

            return(new VideoFile(result));
        }
Ejemplo n.º 2
0
        public static void LoadAll(IHost host, ModelLoadContext ctx, int infoLim, out VBuffer <ReadOnlyMemory <char> >[] keyValues, out ColumnType[] kvTypes)
        {
            Contracts.AssertValue(host);
            host.AssertValue(ctx);

            using (var ch = host.Start("LoadTextValues"))
            {
                // Try to find the key names.
                VBuffer <ReadOnlyMemory <char> >[] keyValuesLocal = null;
                ColumnType[] kvTypesLocal = null;
                CodecFactory factory      = null;
                const string dirFormat    = "Vocabulary_{0:000}";
                for (int iinfo = 0; iinfo < infoLim; iinfo++)
                {
                    ctx.TryProcessSubModel(string.Format(dirFormat, iinfo),
                                           c =>
                    {
                        // Load the lazily initialized structures, if needed.
                        if (keyValuesLocal == null)
                        {
                            keyValuesLocal = new VBuffer <ReadOnlyMemory <char> > [infoLim];
                            kvTypesLocal   = new ColumnType[infoLim];
                            factory        = new CodecFactory(host);
                        }
                        Load(ch, c, factory, ref keyValuesLocal[iinfo]);
                        kvTypesLocal[iinfo] = new VectorType(TextType.Instance, keyValuesLocal[iinfo].Length);
                    });
                }

                keyValues = keyValuesLocal;
                kvTypes   = kvTypesLocal;
                ch.Done();
            }
        }
Ejemplo n.º 3
0
        public static void SaveAll(IHost host, ModelSaveContext ctx, int infoLim, VBuffer <ReadOnlyMemory <char> >[] keyValues)
        {
            Contracts.AssertValue(host);
            host.AssertValue(ctx);
            host.AssertValueOrNull(keyValues);

            if (keyValues == null)
            {
                return;
            }

            using (var ch = host.Start("SaveTextValues"))
            {
                // Save the key names as separate submodels.
                const string dirFormat = "Vocabulary_{0:000}";
                CodecFactory factory   = new CodecFactory(host);

                for (int iinfo = 0; iinfo < infoLim; iinfo++)
                {
                    if (keyValues[iinfo].Length == 0)
                    {
                        continue;
                    }
                    ctx.SaveSubModel(string.Format(dirFormat, iinfo),
                                     c => Save(ch, c, factory, ref keyValues[iinfo]));
                }
                ch.Done();
            }
        }
        public virtual ActionResult Input()
        {
            try
            {
                using (var bodyStream = new StreamReader(Request.Body))
                {
                    var     bodyText = bodyStream.ReadToEndAsync().GetAwaiter().GetResult();
                    dynamic json     = JsonConvert.DeserializeObject(bodyText);
                    var     action   = CodecFactory.GetCodecAction((string)json.Action);
                    // if action not found
                    if (action == null)
                    {
                        return(Json(ReturnResult <string> .Fail("Action not found")));
                    }

                    //TODO: add parameters
                    var tile = Tile.FromStrings(new Triplet <string>(
                                                    json.Inputs.X, json.Inputs.Y, json.Inputs.Z),
                                                new IntegerTileSerializer());

                    var result = action.DoAction(tile);
                    return(Json(result.GetStrings(TileSerializerFactory.GetDefaultSerizlizer())));
                }
            }
            catch (Exception ex)
            {
                return(Json(ReturnResult <string> .Fail(ex.Message)));
            }
        }
Ejemplo n.º 5
0
        private ICodecFactory BuildFactory()
        {
            ICodecFactory codecFactory = new CodecFactory();

            codecFactory.RegisterCodec(OpusDefaults.CodecId, new OpusSettings(), s => new OpusEncoder(s), s => new OpusDecoder(s));

            return(codecFactory);
        }
Ejemplo n.º 6
0
        static MusicFile()
        {
            soundOut     = new DirectSoundOut();
            codecFactory = CodecFactory.Instance;

            soundOut.Stopped += (sender, args) => {
                FileFinishedPlaying?.Invoke(LastFilePlayed);
            };
        }
Ejemplo n.º 7
0
        public void Container_GenericWriterUsingCodecFactoryWithNullCodecName()
        {
            const string WriterSchema =
                @"{
                 ""name"":""RecordContainingArray"",
                 ""type"":""record"",
                 ""fields"":
                           [
                                {""name"":""IntField"", ""type"":""int""},
                           ]
             }";

            var codecFactory = new CodecFactory();

            using (AvroContainer.CreateGenericWriter(WriterSchema, this.resultStream, codecFactory.Create(null)))
            {
            }
        }
Ejemplo n.º 8
0
        private void Initalize()
        {
            m_serializerFactory    = new Ch.Elca.Iiop.Marshalling.SerializerFactory();
            m_codecFactory         = new CodecFactoryImpl(m_serializerFactory);
            m_argSerializerFactory =
                new Ch.Elca.Iiop.Marshalling.ArgumentsSerializerFactory(m_serializerFactory);
            Codec iiopUrlUtilCodec =
                m_codecFactory.create_codec(
                    new Encoding(ENCODING_CDR_ENCAPS.ConstVal,
                                 1, 2));

            m_iiopUrlUtil =
                IiopUrlUtil.Create(iiopUrlUtilCodec, new object[] {
                Ch.Elca.Iiop.Services.CodeSetService.CreateDefaultCodesetComponent(iiopUrlUtilCodec)
            });
            m_serializerFactory.Initalize(m_serializerFactoryConfig,
                                          m_iiopUrlUtil);
        }
Ejemplo n.º 9
0
        public MKVFileSource(Document document)
        {
            _Document = document;
            _Segment  = document.Segments[0];
            //활성화된 트랙에서 필요한 코덱리스트를 생성
            var codecs = CodecFactory.Create(_Segment.Tracks[0].TrackEntry.Where(x => x.FlagEnabled == 1).ToList());

            //사용가능한 모든 코덱 추가
            UsableCodecs = codecs.Where(x => x.IsSupported).Cast <KnownCodec>();
            //사용가능한 미디어 코덱만 추가
            UsableMediaCodecs = UsableCodecs.Where(x => x.CodecType == TrackTypes.Video || x.CodecType == TrackTypes.Audio);
            //사용가능한 자막 코덱 리스트를 생성
            UsableSubtitleCodecs = UsableCodecs.Where(x => x.CodecType == TrackTypes.Subtitle);

            //디폴트 비디오 트랙의 코덱
            var videoCodec = UsableMediaCodecs.FirstOrDefault(x => x.CodecType == TrackTypes.Video && x.TrackEntry.FlagDefault == 1);

            if (videoCodec == null)
            {
                videoCodec = UsableMediaCodecs.FirstOrDefault(x => x.CodecType == TrackTypes.Video);
            }

            var audioCodec = UsableMediaCodecs.FirstOrDefault(x => x.CodecType == TrackTypes.Audio && x.TrackEntry.FlagDefault == 1);

            if (audioCodec == null)
            {
                audioCodec = UsableMediaCodecs.FirstOrDefault(x => x.CodecType == TrackTypes.Audio);
            }

            //비디오나 오디오코덱을 사용할 수 없는 경우만 사용 불가능 코덱을 저장
            if (videoCodec == null || audioCodec == null)
            {
                //사용 불가능한 미디어 코덱 저장
                UnusableMediaCodecs = codecs.Where(x => !x.IsSupported && (x.CodecType == TrackTypes.Video || x.CodecType == TrackTypes.Audio));
            }
            else
            {
                UnusableMediaCodecs = new List <ICodec>();
                //디폴트 비디오/오디오 트랙으로 미디어 디스크립터 생성
                CreateMediaStreamSource(audioCodec);
            }
        }
Ejemplo n.º 10
0
        private static void Load(IChannel ch, ModelLoadContext ctx, CodecFactory factory, ref VBuffer <ReadOnlyMemory <char> > values)
        {
            Contracts.AssertValue(ch);
            ch.CheckValue(ctx, nameof(ctx));
            ctx.CheckAtModel(GetVersionInfo());

            // *** Binary format ***
            // Codec parameterization: A codec parameterization that should be a ReadOnlyMemory codec
            // int: n, the number of bytes used to write the values
            // byte[n]: As encoded using the codec

            // Get the codec from the factory, and from the stream. We have to
            // attempt to read the codec from the stream, since codecs can potentially
            // be versioned based on their parameterization.
            IValueCodec codec;

            // This *could* happen if we have an old version attempt to read a new version.
            // Enabling this sort of binary classification is why we also need to write the
            // codec specification.
            if (!factory.TryReadCodec(ctx.Reader.BaseStream, out codec))
            {
                throw ch.ExceptDecode();
            }
            ch.AssertValue(codec);
            ch.CheckDecode(codec.Type.IsVector);
            ch.CheckDecode(codec.Type.ItemType.IsText);
            var textCodec = (IValueCodec <VBuffer <ReadOnlyMemory <char> > >)codec;

            var bufferLen = ctx.Reader.ReadInt32();

            ch.CheckDecode(bufferLen >= 0);
            using (var stream = new SubsetStream(ctx.Reader.BaseStream, bufferLen))
            {
                using (var reader = textCodec.OpenReader(stream, 1))
                {
                    reader.MoveNext();
                    values = default(VBuffer <ReadOnlyMemory <char> >);
                    reader.Get(ref values);
                }
                ch.CheckDecode(stream.ReadByte() == -1);
            }
        }
Ejemplo n.º 11
0
        public virtual ActionResult Input()
        {
            dynamic json = GetJsonObject(Request.InputStream);

            var action = CodecFactory.GetCodecAction((string)json.Action);

            // if action not found
            if (action == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            //TODO: add parameters

            var tile = Tile.FromStrings(new Triplet <string>(
                                            json.Inputs.X, json.Inputs.Y, json.Inputs.Z),
                                        new IntegerTileSerializer());

            var result = action.DoAction(tile);

            return(Json(result.GetStrings(TileSerializerFactory.GetDefaultSerizlizer())));
        }
Ejemplo n.º 12
0
        public FileInfo Convert(string fileName, string format)
        {
            var      file        = new VideoFile(fileName);
            var      extractFile = new CodecFactory().ExtractFile(file);
            FileInfo fileInfo    = new FileInfo(fileName);

            byte[] buff = new byte[] { Buffer.GetByte(new char[] { }, 0) };
            var    d    = ToDouble(buff, 0);

            if (format == "mp4")
            {
                StreamWriter wr = StreamWriter.Null;
                wr.WriteLine(buff.ToString());
            }
            else
            {
                buff = new[] { Buffer.GetByte(new byte[] { }, 0) };
                StreamWriter wr = StreamWriter.Null;
                wr.WriteLine(buff.ToString());
            }
            return(fileInfo);
        }
        public AudioFile Convert(string fileName, string format)
        {
            var file       = new AudioFile(fileName);
            var sourceCode = CodecFactory.Extract(file);

            Console.WriteLine(sourceCode);

            // you could implement switch case for different formats
            if (format == "mp3")
            {
                var destinationCodec = new MP3CompressionCodec();
                var buffer           = BitrateReader.read(fileName, sourceCode);
                Console.WriteLine(buffer);
                var result = BitrateReader.convert(buffer, destinationCodec);
                Console.WriteLine(result);
                result = (new AudioMixer()).fix(result);
                Console.WriteLine(result);
                Console.WriteLine("finishing your Audio convertor");
                return(new AudioFile(result));
            }
            Console.WriteLine("can't convert undefined format");
            return(file);
        }
        public void Container_GenericWriterUsingCodecFactoryWithInvalidCodecName()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                const string WriterSchema =
                    @"{
                         ""name"":""RecordContainingArray"",
                         ""type"":""record"",
                         ""fields"":
                                   [
                                        {""name"":""IntField"", ""type"":""int""},
                                   ]
                        }";

                var codecFactory = new CodecFactory();

                using (AvroContainer.CreateGenericWriter(WriterSchema,
                                                         this.resultStream, codecFactory.Create("InvalidName")))
                {
                }
            }
                                              );
        }
Ejemplo n.º 15
0
    static void Main(string[] args)
    {
        Cdr d = new Cdr();

        d.setString(codecBinding.MessageType, "A");
        d.setString(codecBinding.UserName, "username");
        d.setString(codecBinding.Password, "password");
        d.setString(codecBinding.NewPassword, "password1");
        d.setInteger(codecBinding.MessageVersion, 0);

        Console.WriteLine(d.toString());

        CodecFactory cf       = new CodecFactory();
        Codec        lseCodec = cf.getCodec("lse");

        Neueda.Codecs.Buffer b = lseCodec.encode(d);

        Console.WriteLine(b);

        Cdr decoded = lseCodec.decodeBuffer(b).getCdr();

        Console.WriteLine(decoded.toString());
    }
        public FileInfo ConvertVideo(String fileName, String format)
        {
            Console.WriteLine("VideoConversionFacade: conversion started.");
            VideoFile file        = new VideoFile(fileName);
            ICodec    sourceCodec = CodecFactory.Extract(file);
            ICodec    destinationCodec;

            if (format.Equals("mp4"))
            {
                destinationCodec = new OggCompressionCodec();
            }
            else
            {
                destinationCodec = new MPEG4CompressionCodec();
            }
            VideoFile buffer             = BitrateReader.Read(file, sourceCodec);
            VideoFile intermediateResult = BitrateReader.Convert(buffer, destinationCodec);
            FileInfo  result             = (new AudioMixer()).Fix(intermediateResult);

            Console.WriteLine("VideoConversionFacade: conversion completed.");
            Console.ReadKey();
            return(result);
        }
Ejemplo n.º 17
0
        private bool read(int codecType, sceAtrac3plus.AtracFileInfo atracFileInfo)
        {
            codec = CodecFactory.getCodec(codecType);
            if (codec == null)
            {
                return(false);
            }

            int result = codec.init(atracFileInfo.atracBytesPerFrame, atracFileInfo.atracChannels, atracFileInfo.atracChannels, atracFileInfo.atracCodingMode);

            if (result < 0)
            {
                return(false);
            }

            AudioFormat audioFormat = new AudioFormat(44100, 16, atracFileInfo.atracChannels, true, false);

            DataLine.Info info = new DataLine.Info(typeof(SourceDataLine), audioFormat);
            try
            {
                mLine = (SourceDataLine)AudioSystem.getLine(info);
                mLine.open(audioFormat);
            }
            catch (LineUnavailableException)
            {
                return(false);
            }
            mLine.start();

            inputOffset        = atracFileInfo.inputFileDataOffset;
            inputPosition      = inputOffset;
            inputBytesPerFrame = atracFileInfo.atracBytesPerFrame;
            channels           = atracFileInfo.atracChannels;

            return(true);
        }
Ejemplo n.º 18
0
 internal ORBInitInfoImpl(OrbServices orb) {
     m_orb = orb;
     m_manager = orb.InterceptorManager;
     m_codecFactory = orb.CodecFactory;
 }
Ejemplo n.º 19
0
        private static void Save(IChannel ch, ModelSaveContext ctx, CodecFactory factory, ref VBuffer <ReadOnlyMemory <char> > values)
        {
            Contracts.AssertValue(ch);
            ch.CheckValue(ctx, nameof(ctx));
            ctx.CheckAtModel();
            ctx.SetVersionInfo(GetVersionInfo());

            // *** Binary format ***
            // Codec parameterization: A codec parameterization that should be a ReadOnlyMemory codec
            // int: n, the number of bytes used to write the values
            // byte[n]: As encoded using the codec

            // Get the codec from the factory
            IValueCodec codec;
            var         result = factory.TryGetCodec(new VectorType(TextType.Instance), out codec);

            ch.Assert(result);
            ch.Assert(codec.Type.IsVector);
            ch.Assert(codec.Type.VectorSize == 0);
            ch.Assert(codec.Type.ItemType.RawType == typeof(ReadOnlyMemory <char>));
            IValueCodec <VBuffer <ReadOnlyMemory <char> > > textCodec = (IValueCodec <VBuffer <ReadOnlyMemory <char> > >)codec;

            factory.WriteCodec(ctx.Writer.BaseStream, codec);
            using (var mem = new MemoryStream())
            {
                using (var writer = textCodec.OpenWriter(mem))
                {
                    writer.Write(ref values);
                    writer.Commit();
                }
                ctx.Writer.WriteByteArray(mem.ToArray());
            }

            // Make this resemble, more or less, the auxiliary output from the TermTransform.
            // It will differ somewhat due to the vector being possibly sparse. To distinguish
            // between missing and empty, empties are not written at all, while missings are.
            var v = values;

            char[] buffer = null;
            ctx.SaveTextStream("Terms.txt",
                               writer =>
            {
                writer.WriteLine("# Number of terms = {0} of length {1}", v.Count, v.Length);
                foreach (var pair in v.Items())
                {
                    var text = pair.Value;
                    if (text.IsEmpty)
                    {
                        continue;
                    }
                    writer.Write("{0}\t", pair.Key);
                    // REVIEW: What about escaping this, *especially* for linebreaks?
                    // Do C# and .NET really have no equivalent to Python's "repr"? :(
                    if (text.IsEmpty)
                    {
                        writer.WriteLine();
                        continue;
                    }
                    Utils.EnsureSize(ref buffer, text.Length);

                    var span = text.Span;
                    for (int i = 0; i < text.Length; i++)
                    {
                        buffer[i] = span[i];
                    }

                    writer.WriteLine(buffer, 0, text.Length);
                }
            });
        }
Ejemplo n.º 20
0
 internal ORBInitInfoImpl(OrbServices orb)
 {
     m_orb          = orb;
     m_manager      = orb.InterceptorManager;
     m_codecFactory = orb.CodecFactory;
 }
 internal GiopMessageBodySerialiser(ArgumentsSerializerFactory argSerFactory) {
     m_serFactory = argSerFactory.SerializerFactory;
     m_argSerFactory = argSerFactory;
     m_codecFactory = new CodecFactoryImpl(m_serFactory);
 }
Ejemplo n.º 22
0
 protected virtual void RegisterFactory(CodecFactory factory)
 {
     this.factories.Add(factory);
 }
Ejemplo n.º 23
0
 private void Initalize()
 {
     m_serializerFactory = new Ch.Elca.Iiop.Marshalling.SerializerFactory();
     m_codecFactory = new CodecFactoryImpl(m_serializerFactory);
     m_argSerializerFactory =
         new Ch.Elca.Iiop.Marshalling.ArgumentsSerializerFactory(m_serializerFactory);
     Codec iiopUrlUtilCodec =
             m_codecFactory.create_codec(
                                new Encoding(ENCODING_CDR_ENCAPS.ConstVal,
                                             1, 2));
     m_iiopUrlUtil =
         IiopUrlUtil.Create(iiopUrlUtilCodec, new object[] { 
             Ch.Elca.Iiop.Services.CodeSetService.CreateDefaultCodesetComponent(iiopUrlUtilCodec)});
     m_serializerFactory.Initalize(m_serializerFactoryConfig,
                                   m_iiopUrlUtil);
 }
Ejemplo n.º 24
0
 public virtual void initCodec(int codecType)
 {
     codec            = CodecFactory.getCodec(codecType);
     CodecInitialized = false;
 }
Ejemplo n.º 25
0
 public ChoAvroReader <T> WithCodecFactory(CodecFactory cf)
 {
     Configuration.CodecFactory = cf;
     return(this);
 }
Ejemplo n.º 26
0
 public static object Read(string filename, CodecFactory sourceCodec)
 {
     throw new System.NotImplementedException();
 }